0

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

Neil
  • 7,937
  • 22
  • 87
  • 145
  • This question asked many times in stackoverflow. Didn't you try that all? – Kalana Apr 30 '20 at 06:43
  • Maybe that helps you, was asked before: [Link](https://stackoverflow.com/questions/28154066/how-to-convert-datetime-to-integer-in-python) – Styx1337 Apr 30 '20 at 06:56
  • That is the "OLE automation date format". Mention that. So people would not get confused and you will get proper answer. – Dishin H Goyani Apr 30 '20 at 07:04

1 Answers1

1

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)
Jani Ahmad
  • 11
  • 1