I have following datetime in Python and want to convert it to numeric
2020-04-01 12:30:01
When I convert this to number in excel it returns 43922.5208449074
. How to get the same number in Python?
I tried with following
datetime.fromisoformat('2020-04-01 12:30:01').timestamp()
But it does not return me the same number. How can we do it in Python
If i am understanding your problem, you can use it
# Importing datetime.
from datetime import datetime
# Creating a datetime object so we can test.
a = datetime.now()
# Converting a to string in the desired format (YYYYMMDD) using strftime
# and then to int.
a = int(a.strftime('%Y%m%d'))
print (a)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.