In Matlab, when I run "datenum" function as the following;
datenum(1970, 1, 1);
I get the following output:
719529
I'm trying to find the equivalent function or script which is gonna give me the same output. But, unfortunately I couldn't find an enough explanation on the internet to do this.
I have looked at this tutorial: https://docs.python.org/2/library/datetime.html, but it didn't help.
Could you tell me, how can I get the same output in python?
Thanks,
You can substract
date
objects in Python:Just take care to use an epoch that is useful to your needs.
I would use the datetime module and the toordinal() function
To get the date you got you would use
or for easier conversion
I believe the reason the date is off is due to the fact datenum starts its counting from january 0, 0000 which this doesn't recognize as a valid date. You will have to counteract the change in the starting date by adding one to the year and day. The month doesn't matter because the first month in datetime is equal to 0 in datenum
The previous answers return an integer. MATLAB's datenum does not necessarily return an integer. The following code retuns the same answer as MATLAB's datenum: