Python ProgrammingPython Programming

Python get the difference between two datetime objects into seconds

import datetime

time1 = datetime.datetime.strptime('19 01 2021', '%d %m %Y')
time2 = datetime.datetime.strptime('25 01 2021', '%d %m %Y')

difference = time2 - time1
print(difference)

seconds = difference.total_seconds()
print(seconds)
Output
6 days, 0:00:00
518400.0