Home > Software engineering >  how to convert 5 digits number to date in python
how to convert 5 digits number to date in python

Time:12-03

I would like to convert 44562 int64 data type (5 digits number) to date format like this 1/1/2022.

Out[5]: 
0    44562
1    44562
2    44563
3    44563
4    44564
Name: Date, dtype: int64

I try with

df['Date'].apply(lambda x: (datetime.utcfromtimestamp(0)   timedelta(int(x))).strftime("%m-%d-%Y")) 

but output date is not correct. Please help to fix the issue.

Out[13]: 
0    01-03-2092
1    01-03-2092
2    01-04-2092
3    01-04-2092
4    01-05-2092
Name: Date2, dtype: object

CodePudding user response:

You very nearly had it:

df['Date'].apply(lambda x: (datetime(1899, 12, 30)   timedelta(days=int(x))).strftime("%m/%d/%Y"))
  • Related