datetime.exceltime
datetime: E = exceltime (T)
datetime: E = exceltime (T, dateType)
Convert datetime array to Excel serial date numbers.
E = exceltime (T) returns a double array
E of the same size as T holding the Excel serial date number
of each element, using the Excel 1900 date system, in which the fractional
part represents the time of day. As in Excel, the year 1900 is treated as
a leap year, so serial numbers on or after 1900-03-01 account for the
nonexistent date 1900-02-29.
E = exceltime (T, dateType) selects the date
system: '1900' (default) or '1904'. The 1904 system
counts days from 1904-01-01 and has no leap-year anomaly, so a date
before 1900-03-01 is a plain day count and its serial is one greater than
MATLAB returns; MATLAB derives the 1904 serial from the 1900 one and
carries the nonexistent 1900-02-29 into a system that never had it.
Excel stores no negative serial in either system, so this affects only
dates neither can represent, where the value returned here is the one
datetime (E, 'ConvertFrom', 'excel1904') converts back
exactly.
The time zone of a zoned T is ignored; its wall-clock components are
used. Not-A-Time (NaT) values are returned as NaN.
Source Code: datetime
exceltime returns an Excel serial date number. The '1900' system is the default; pass '1904' for the Excel 1904 system.
t = datetime (2024, 3, 9, 6, 0, 0)
t = datetime 09-Mar-2024 06:00:00
exceltime (t)
ans = 4.5360e+04
exceltime (t, '1904')
ans = 4.3898e+04