How do I read a date in Excel format in Python ?

How do I read a date in Excel format in Python ?

Asked on January 8, 2019 in Excel.
Add Comment


  • 3 Answer(s)

    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.
    Answered on January 8, 2019.
    Add Comment

    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)
          )
    
    Answered on January 8, 2019.
    Add Comment

        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)
    
    Answered on January 8, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.