Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

Python Difference between two dates and times

from datetime import datetime, date

t1 = date(year = 2018, month = 7, day = 12)
t2 = date(year = 2017, month = 12, day = 23)
t3 = t1 - t2
print("t3 =", t3)

t4 = datetime(year = 2018, month = 7, day = 12, hour = 7, minute = 9, second = 33)
t5 = datetime(year = 2019, month = 6, day = 10, hour = 5, minute = 55, second = 13)
t6 = t4 - t5
print("t6 =", t6)

print("type of t3 =", type(t3)) 
print("type of t6 =", type(t6))
Comment

Difference in seconds between datetime

$start = new DateTime('2011-12-31 00:00:00');
$end = new DateTime('2021-01-01 00:00:00');

echo $end->getTimestamp() - $start->getTimestamp(); // output: 284169600
Comment

PREVIOUS NEXT
Code Example
Python :: undefined in python 
Python :: add item to python dictionary 
Python :: python define class 
Python :: opencv namedwindow 
Python :: django order by foreign key count 
Python :: pyqt remove widget 
Python :: random python range 
Python :: gráfico barras python 
Python :: remove multiple strings from list python 
Python :: pyodbc cursor create list of dictionaries 
Python :: thread syntax in python 
Python :: initialize a 2d list python 
Python :: getenv python 
Python :: how to learn python 
Python :: python create dummy dataframe 
Python :: user information in python 
Python :: ipynb import 
Python :: python string cut last n characters 
Python :: os chdir python 
Python :: delete row if contains certain text pandas 
Python :: how to have player input in python 
Python :: file uploads django 
Python :: pandas dataframe sort by column 
Python :: knn with sklearn 
Python :: how to get python list length 
Python :: break in python 
Python :: python if statement 
Python :: kivy dropdown list 
Python :: numpy sqrt 
Python :: turn columns into one column as list python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =