Search code examples
pythonxlrd

Python - Importing Excel dates converts to number


I'm trying to learn to the use the xlrd package in Python to read Excel files, and I have made a sample file which contains a list of chronological dates and in the second column the day of the week it corresponds to.

The problem is that when I read in the data it displays it as a number. How can I get the date to display the way it is supposed to?

[u'Date', u'Day']
[41162.0, u'Monday']
[41163.0, u'Tuesday']
[41164.0, u'Wednesday']
[41165.0, u'Thursday']
[41166.0, u'Friday']

Solution

  • you want

    wb = xlrd.open_workbook("somewb.xls")
    my_date_tuple = xlrd.xldate_as_tuple(xls_timestamp_number,wb.datemode)
    

    which then returns a date tuple that is much easier to work with :)