Created
January 29, 2013 10:02
-
-
Save zertrin/4663169 to your computer and use it in GitHub Desktop.
Function to convert a Python datetime to a Matlab datenum.
From http://stackoverflow.com/questions/8776414/python-datetime-to-matlab-datenum/9260102#9260102
This file contains hidden or 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
from datetime import datetime, timedelta | |
def datetime2matlabdn(dt): | |
ord = dt.toordinal() | |
mdn = dt + timedelta(days = 366) | |
frac = (dt-datetime(dt.year,dt.month,dt.day,0,0,0)).seconds / (24.0 * 60.0 * 60.0) | |
return mdn.toordinal() + frac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just add the following line
dt = dt.replace(tzinfo=None)
this function doesn't really give the same results as Matlab
ex:
there's a difference by 4 values