Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert date to timestamp using Python?

I need to convert this result to timestamp:

>>> print (datetime.date(2010, 1, 12) + datetime.timedelta(days = 3))
2010-01-15

I need to compare the value with this timestamp:

>>> datetime.datetime.now()
2011-10-24 10:43:43.371294

How can I achieve this?

like image 998
André Avatar asked Dec 07 '25 08:12

André


1 Answers

I need to convert this result to timestamp

import time


mydate = datetime.date(2010, 1, 12) + datetime.timedelta(days = 3)
time.mktime(mydate.timetuple())

I need to compare the value with this timestamp:

a = datetime.datetime(2010, 1, 12) + datetime.timedelta(days = 3)
b = datetime.datetime.now()

a < b 
a > b 
a == b 
like image 58
Constantinius Avatar answered Dec 08 '25 22:12

Constantinius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!