What calendar system does MATLAB use?
18 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: James Tursa
on 27 Nov 2023
What calendar system does MATLAB use?
For example, does MATLAB use the Julian calendar?
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
MATLAB does not use any particular calendar system, such as the Julian or Gregorian calendar.
Please refer the documentation on the command DATENUM for a detailed description on how MATLAB calculates the date. You can use either 'help datenum' or 'doc datenum' in MATLAB command prompt to get detailed information on this command.
For MATLAB, the time functions begin with the CLOCK function, which returns a six-element vector:
C = [year month day hour minutes seconds]
For example, if you have the following code:
C = [2001 5 21 15 19 29];
DATESTR reformats this to:
datestr(C)
= 21-May-2001 15:19:29
DATENUM is a way of summarizing the six clock components in one double precision number (with an an accuracy of about 1.0e-5 seconds).
T = datenum(C)
which returns 730992.6385300926.
So, datenum(C) = 0 corresponds to C = [0 0 0 0 0 0], which is "day 0 of month 0 of year 0". Of course, as far as we know, no one has ever used such a calendar, but it would be the logical extrapolation of our current calendar back to times around year 0 A.D.
The Julian day number, JD, and MATLAB's datenum, T, are measuring the same thing -- number of days (and fractions of days) since some arbitrary ancient origin. One is simply an offset of the other. The Julian day number starts at noon, while the MATLAB datenum starts at midnight, so the offset involves half a day.
Here is the formula, applied to the time when you want to write this:
JD = T + 1721058.5
This returns 2452051.138530092. If you want to ignore the fraction, use the following code:
fix(JD)
which will return 2452051.
0 Comments
More Answers (1)
James Tursa
on 17 Nov 2023
Edited: James Tursa
on 27 Nov 2023
I know this is an old post, but the accepted answer is a bit misleading. MATLAB certainly does use a specific calendar system. In particular it uses the Gregorian Calendar, and pre 15-Oct-1582 dates are assumed to be backwards extensions of this calendar rather than Julian Calendar. A comparison:
Julian Calendar with jump to Gregorian Calendar:
All years divisible by 4 are leap years (for Astronomical Convention the year 0 exists also)
The dates from Oct 5, 1582 through Oct 14, 1582 inclusive don’t exist (jump to Gregorian Calendar)
Backwards extension of Gregorian Calendar:
Years divisible by 4 except years divisible by 100 that are not divisible by 400 are leap years
The dates from Oct 5, 1582 through Oct 14, 1582 inclusive do exist
To see the difference, simply generate a datetime array near this event:
dt = datetime(1582,10,4:15)'
format longg
jd = juliandate(dt)
You can see that the "missing" dates for the jump from Julian Calendar to Gregorian Calendar are in fact present, and that these dates are simply backwards extensions of the Gregorian Calendar. Also, look at the dates near a Julian Leap Day:
dt = datetime(1500,2,28:30)'
jd = juliandate(dt)
Although Feb 29, 1500 should exist because it is a leap year in the Julian Calendar, it does not exist in the datetime array. Again, this is because MATLAB is using a backwards extension of Gregorian Calendar leap year rules.
And Julian Date 0 is associated with this calendar date:
datetime(0,'ConvertFrom','juliandate')
Finally, note that the MATLAB functions will not agree with other authorities (Astronomical Algorithms by Jean Meeus and JPL/NASA website) on Julian Dates and calendar dates for these pre Gregorian epoch events. E.g., from this site:
Compare the following output with the above:
You can see that the calendar dates and Julian Dates do not match MATLAB.
Again, this isn't a MATLAB error, it is just a calendar convention difference that users should be aware of when working with pre Gregorian Calendar dates.
0 Comments
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!