How do I read a date in Excel format in Python ?
Try this best solution :
- On the other hand, use xldate_as_tuple to convert it to a python date, so now can read that dates are continually stored as numbers.
- Make sure that, when compare between PyPl and xlrd, the version on the PyPI seems more up-to-date than the one available on xlrd’s website.
Use this version of bare-knuckle no-seat-belts use-at-own-risk :
import datetime def minimalist_xldate_as_datetime(xldate, datemode): // # datemode: 0 for 1900-based, 1 for 1904-based return ( datetime.datetime(1899, 12, 30) + datetime.timedelta(days=xldate + 1462 * datemode) )
This is better method xlrd.xldate_as_tuple, but try this method xlrd.xldate.xldate_as_datetime method to converts to datetime.
import xlrd wb = xlrd.open_workbook(filename) xlrd.xldate.xldate_as_datetime(41889, wb.datemode) => datetime.datetime(2014, 9, 7, 0, 0)