How do I read Excel file in Python?

houdinihound at yahoo.com houdinihound at yahoo.com
Thu Oct 5 21:49:53 CEST 2006


> > >>> excel_date = 38938.0
> > >>> python_date = datetime.date(1900, 1, 1) + datetime.timedelta(days=excel_date)
> > >>> python_date
> > datetime.date(2006, 8, 11)
>
> Err, that's the wrong answer, isn't it? Perhaps it shoud be
> datetime.date(1900, 1, 29)?

Actually was about to post same solution and got same results. (BTW
Simon, the OP date is Aug 9th, 2006).  Scratched head and googled for
excel date calculations... found this bug where it treats 1900 as leap
year incorrectly:
http://www.ozgrid.com/Excel/ExcelDateandTimes.htm

Plus it treats 1 jan 1900 as day 1, not 0 so just subtract 2 in the
calc:
>>>python_date = datetime.date(1900, 1, 1) + datetime.timedelta(days=excel_date - 2)
>>> python_date
datetime.date(2006, 8, 9)

HTH.




More information about the Python-list mailing list