python - How to convert a given ordinal number (from Excel) to a date -


i have value 38142 need convert date format using python. if use number in excel , right click , format cell @ time value converted 04/06/2004 , need same result using python. how can achieve this

the offset in excel in 1900/01/01; add number of days timedelta:

from datetime import date, timedelta  def from_excel_ordinal(ordinal, _epoch=date(1900, 1, 1)):     if ordinal > 59:         ordinal -= 1  # excel leap year bug, 1900 not leap year!     return _epoch + timedelta(days=ordinal - 1)  # epoch day 1 

i had adjust ordinal 2 date after 1900/02/28; excel has inherited leap year bug lotus 1-2-3 , treats 1900 leap year. code above returns date(1900, 2, 28) both 59 , 60 correct this.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -