Created
April 3, 2014 17:48
-
-
Save OmarArain/9959241 to your computer and use it in GitHub Desktop.
convert Excel serial date to python datetime.datetime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def xldate_to_datetime(xldate): | |
temp = datetime.datetime(1900, 1, 1) | |
delta = datetime.timedelta(days=xldate) | |
return temp+delta |
I found the same as zongokevin and If you don't mind importing pandas
here's an alternative
import pandas as pd
def convert_excel_time(excel_time):
'''
converts excel float format to pandas datetime object
round to '1min' with
.dt.round('1min') to correct floating point conversion innaccuracy
'''
return pd.to_datetime('1899-12-30') + pd.to_timedelta(excel_time,'D')
Thanks a lot guys.It worked for me when I used
temp = datetime.datetime(1899, 12, 30)
Oh thank you. Saved me.
I found the same as zongokevin and If you don't mind importing pandas
here's an alternativeimport pandas as pd def convert_excel_time(excel_time): ''' converts excel float format to pandas datetime object round to '1min' with .dt.round('1min') to correct floating point conversion innaccuracy ''' return pd.to_datetime('1899-12-30') + pd.to_timedelta(excel_time,'D')
thanks
Great!
@alistairwalsh @oag335
Thanks guys !
I found the same as zongokevin and If you don't mind importing pandas
here's an alternativeimport pandas as pd def convert_excel_time(excel_time): ''' converts excel float format to pandas datetime object round to '1min' with .dt.round('1min') to correct floating point conversion innaccuracy ''' return pd.to_datetime('1899-12-30') + pd.to_timedelta(excel_time,'D')
thanks!! It really helped me!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, It didtn't work for me to read the Excel file on windows, I make those changes to be able to read it
def xldate_to_datetime(xldate):
temp = datetime.datetime(1899, 12, 30)
delta = datetime.timedelta(days=xldate)
return temp+delta