When I read an Excel file with python's xlrd etc., the date displayed on Excel is replaced with a 5-digit mysterious number such as ** 41496 **.
This seems to be because in Excel, the date starts from January 1, 1900 (the first day), and the date data is held as a numerical value obtained by adding the number of days from that.
--For example, 42884 on May 29, 2017. It seems that 42884 days have passed since January 1, 1900. -(By the way, if you put it in 1800 or Excel, it will not be converted numerically. It will be negative)
To convert this number to a date format in python, use timedelta and add it as follows: Substitute an Excel number for num
def excel_date(num):
from datetime import datetime, timedelta
return(datetime(1899, 12, 30) + timedelta(days=num))
For example, entering 41496 returns the datetime of August 10, 2013.
excel_date(41946)
> datetime.datetime(2013, 8, 10, 0, 0)
Recommended Posts