Python Forum
Convert date integers (ex. 43831) to regular format - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Convert date integers (ex. 43831) to regular format (/thread-30959.html)



Convert date integers (ex. 43831) to regular format - Galven - Nov-15-2020

Hi,

I'm currently learning Python 3 and I am struggling with converting date integers into another format.
The dates have the format 43831, 43832, etc. 43831 being 01-01-2020.

What line of code I need to use to convert my whole column into, let's say, a date format "dd-mm-yyyy"?


[Image: Capture.png]
Screenshot if the above deson't work: https://ibb.co/rm044MN
I tried things, in vain.

Thank you.


RE: Convert date integers (ex. 43831) to regular format - buran - Nov-15-2020

post your code, sample input, expected output, full error traceback as text, using proper BBCode tags.
Don't post images.
See BBcode help for more info.
Are these comming from Excel?


RE: Convert date integers (ex. 43831) to regular format - bowlofred - Nov-15-2020

Something like this would be a start...

>>> from datetime import datetime,timedelta
>>> (datetime(1900, 1, 1) + timedelta(days=43831-2)).strftime("%d-%m-%Y")
'01-01-2020'