MATLAB: Datenum: how many seconds in a day

datedatenumseconds

Datenum converts a date to a number representing the number of days past since a certain initial date. The documentation of datenum doesn't seem to say anything about this, but what is meant exactly by a day?
Is the day exactly 24h, i.e. 86400 (SI) seconds? Or is it a solar day?
If it is the former, how does it match with real life dates? By adding leap seconds? If so, a day is not (necessarily) exactly 86400 seconds; and how do I know when there are leap seconds and how many?
If it is the latter, how do I know how many (SI) seconds there were/are/will be in that day?
Thanks in advance

Best Answer

With regards to the datenum and related functions, MATLAB days are exactly 24h (86400s) always. There is accounting for leap days in calendar date conversions, but NO accounting for leap seconds. There is also no accounting for time zones. So it is up to the user to use the functions properly as MATLAB gives you no help here. That is, you can use the datenum family of functions to work with local times or UTC based times or TT based times, but you need to know what you are doing and make any adjustments (time zone, leap seconds, etc) yourself to get the correct result.
To quote the doc, the "now" function "... returns the current date and time as a serial date number." Since this is obtained from your computer's clock, and since your computer likely updates its clock from a UTC based server with time zone correction, what you get with the "now" function is a local time zone corrected UTC based time. UTC based times have leap seconds applied to them, so it is not a continuous time scale.
If you need to convert to a continuous time scale like TT or GPS, you will need to get a 3rd party conversion function. Basically, a table look up to account for leap seconds and then a constant offset will do the job. For example, astronomical algorithms typically take a TT based time as an input (to get planet positions, etc), so if you are trying to see where a planet is at 10pm tonight you would need to convert that local UTC based time to a TT time before feeding it to the astronomical algorithm. Online programs typically do this conversion for you in the background, but if you are writing a program yourself you would need to include that conversion in your program.
I think I have a MATLAB based UTC -- TT conversion program if you need it, or you might be able to find one in the FEX (I haven't looked).