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

3
  • This question asked many times in stackoverflow. Didn't you try that all? Commented Apr 30, 2020 at 6:43
  • Maybe that helps you, was asked before: Link Commented Apr 30, 2020 at 6:56
  • That is the "OLE automation date format". Mention that. So people would not get confused and you will get proper answer. Commented Apr 30, 2020 at 7:04

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.