I've got .mat file with datenum values (i.e. 735724.3229166666, 735725.6756944444 and etc.).
My goal is transform it into datetime format without losing precision, in other words it should work as precise as it would've worked with matlab.
I am perfectly aware of those answers: Converting Matlab's datenum format to Python
But none of them work as precise, because python rounds everything up after decimal in almost every numerical operation.
For example, those functions I wrote are based on the answers in the link above:
def datenum_to_datetime1(datenum):
days = datenum % 1
return datetime.fromordinal(int(datenum)) \
+ timedelta(days=days) \
- timedelta(days=366)
def datenum_to_datetime2(datenum):
days = np.float_(datenum) % 1
return datetime.fromordinal(int(datenum)) \
+ timedelta(days=days) \
- timedelta(days=366)
def datenum_to_datetime3(datenum):
return pd.to_datetime(datenum-719529, unit='D')
def datenum_to_datetime4(datenum):
origin = np.datetime64('0000-01-01', 'D') - np.timedelta64(1, 'D')
date = datenum * np.timedelta64(1, 'D') + origin
return date
If I try them on 735724.3229166666 , I get:
- 2014-05-05 07:44:59.999997
- 2014-05-05 07:44:59.999997
- 2014-05-05 07:45:00.000028800
- 2014-05-05
Third option is the most precise but with matlab it's still differs. Can someone help?