m2xdate
Converts MATLAB date numbers to Excel date numbers.
Category: Language Fundamentals > Data Types
Syntax
x = m2xdate(m)
Converts the serial date numbers m to the Excel 1900 date system.
x = m2xdate(m, basis)
Selects the Excel date system: 0 for 1900 (default) or 1 for 1904.
Description
MATLAB counts days from year 0 and Excel from 1900 (or 1904 in the Macintosh system), so the two numbering schemes differ by a fixed offset. m2xdate subtracts it and x2mdate adds it back. Fractions of a day, which hold the time of day, carry over unchanged.
The function belongs to the Financial Toolbox in MATLAB.
Input arguments
m- Array of MATLAB serial date numbers, as given by
datenum. basis0or1.
Output arguments
x- Array of Excel serial dates, the same size as
m.
Example
Round trip with Excel dates
m = datenum(2024, 1, 1);
x = m2xdate(m)
x2mdate(x) == m
Output
x = 45292
ans = logical
1