Answers for "date time difference python"

2

python time difference

import datetime
time_1 = datetime.strptime('05:00:00',"%H:%M:%S")
time_2 = datetime.strptime('10:00:00',"%H:%M:%S")

time_interval = time_2 - time_1
print(time_difference)
>>> 5:00:00

OR 
import time
time_1 = time.time()

time.sleep(20)

time_2 = time.time()
time_interval = time_2 - time_1
print(time_interval)
>>> 20.005916118621826

OR 
import datetime
time_1 = datetime.timedelta(hours= 10 , minutes=20, seconds=30)
time_2 = datetime.timedelta(hours= 20, minutes=30, seconds=45)
print(time_2 - time_1)
Posted by: Guest on November-16-2021
1

Date difference in minutes in Python

minutes_diff = (datetime_end - datetime_start).total_seconds() / 60.0
Posted by: Guest on January-08-2021
0

python datetime difference in seconds

import datetime as dt

a = dt.datetime(2013,12,30,23,59,59)
b = dt.datetime(2013,12,31,23,59,59)

(b-a).total_seconds()
Posted by: Guest on June-09-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 "date time difference python"

Python Answers by Framework

Browse Popular Code Answers by Language