programming-examples/python/Date/Calculate two date difference in seconds.py
2019-11-15 12:59:38 +01:00

10 lines
371 B
Python

from datetime import datetime, time
def date_diff_in_Seconds(dt2, dt1):
timedelta = dt2 - dt1
return timedelta.days * 24 * 3600 + timedelta.seconds
#Specified date
date1 = datetime.strptime('2015-01-01 01:00:00', '%Y-%m-%d %H:%M:%S')
#Current date
date2 = datetime.now()
print("\n%d seconds" %(date_diff_in_Seconds(date2, date1)))
print()