Answers for "get the time difference between two dates python"

1

python difference in dates in seconds

future_date = datetime.datetime(1970, 1, 2)
past_date = datetime.datetime(1970, 1, 1)

difference = (future_date - past_date)
Calculate difference in time


total_seconds = difference.total_seconds()
Convert time difference to seconds


print(total_seconds)
OUTPUT
86400.0
Posted by: Guest on October-11-2020
1

time difference between two datetime.time

# Create datetime objects for each time (a and b)
dateTimeA = datetime.datetime.combine(datetime.date.today(), a)
dateTimeB = datetime.datetime.combine(datetime.date.today(), b)
# Get the difference between datetimes (as timedelta)
dateTimeDifference = dateTimeA - dateTimeB
# Divide difference in seconds by number of seconds in hour (3600)  
dateTimeDifferenceInHours = dateTimeDifference.total_seconds() / 3600
Posted by: Guest on January-11-2021

Code answers related to "get the time difference between two dates python"

Python Answers by Framework

Browse Popular Code Answers by Language