Answers for "how to find the difference between two datetime in python"

5

day difference between two dates in python

from datetime import date
d0 = date(2017, 8, 18)
d1 = date(2017, 10, 26)
delta = d1 - d0
print(delta.days)
Posted by: Guest on May-11-2020
3

python get dates between two dates

from datetime import datetime, timedelta

def date_range(start, end):
    delta = end - start  # as timedelta
    days = [start + timedelta(days=i) for i in range(delta.days + 1)]
    return days

start_date = datetime(2008, 8, 1)
end_date = datetime(2008, 8, 3)
    
print(date_range(start_date, end_date))
Posted by: Guest on September-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 "how to find the difference between two datetime in python"

Python Answers by Framework

Browse Popular Code Answers by Language