x2mdate - (Not recommended; use datetime) Excel serial date number to MATLAB serial date number or datetime value - MATLAB (original) (raw)
(Not recommended; use datetime
) Excel serial date number to MATLAB serial date number or datetime
value
Syntax
Description
[MATLABDate](#bu%5Fw1si-1-MATLABDate) = x2mdate([ExcelDateNumber](#bu%5Fw1si-1-ExcelDateNumber),[Convention](#bu%5Fw1si-1-Convention))
converts an array of Excel® serial date numbers to an array of MATLAB® serial date numbers. It converts date numbers using either the 1900 date system or the 1904 date system, as specified byConvention
.
MATLAB date numbers start with 1
= January 1, 0000 CE, hence there is a difference of 693960 relative to the 1900 date system, or 695422 relative to the 1904 date system. This function is useful with Spreadsheet Link™ software.
[MATLABDate](#bu%5Fw1si-1-MATLABDate) = x2mdate(___,[outputType](#bu%5Fw1si-1-outputType))
converts Excel serial date numbers to an array of MATLAB serial date numbers or a datetime
array using an optional input argument for outputType
.
The type of output is determined by an optional outputType
input. If outputType
is "datenum"
, thenMATLABDate
is an array of serial date numbers. IfoutputType
is "datetime"
, thenMATLABDate
is a datetime
array. By default, outputType
is "datenum"
.
Examples
Given Excel® date numbers in the 1904 system, convert them to MATLAB® serial date numbers, and then to character vectors formatted as dates.
ExDates = [35423 35788 36153]; MATLABDate = x2mdate(ExDates, 1)
MATLABDate = 1×3
730845 731210 731575
ans = 3×11 char array '25-Dec-2000' '25-Dec-2001' '25-Dec-2002'
Alternatively, use the optional input outputType
to specify "datetime"
to return a datetime
array.
ExDates = [35423 35788 36153]; MATLABDate = x2mdate(ExDates, 1,"datetime")
MATLABDate = 1×3 datetime 25-Dec-2000 25-Dec-2001 25-Dec-2002
Input Arguments
Excel serial date number, specified as a scalar or vector of Excel serial date numbers.
Data Types: double
Flag for Excel date system, specified as a scalar or vector as a numeric with a value 0
or 1
.Convention
must be either a scalar or else must be the same size as ExcelDateNumber.
When Convention = 0
(default), the Excel 1900 date system is in effect. When Convention = 1
, the Excel 1904 date system in used.
In the Excel 1900 date system, the Excel serial date number 1 corresponds to January 1, 1900 A.D. In the Excel 1904 date system, date number 0 is January 1, 1904 A.D.
Due to a software limitation in Excel software, the year 1900 is considered a leap year. As a result, all DATEVALUEs reported by Excel software between Jan. 1, 1900 and Feb. 28, 1900 (inclusive) differs from the values reported by 1. For example:
- In Excel software, Jan. 1, 1900 =
1
- In MATLAB, Jan. 1, 1900 –
693960
(for 1900 date system) =2
datenum("Jan 1, 1900") - 693960
Data Types: logical
Output date format, specified as "datenum"
or"datetime"
. The outputMATLABDate is in serial date format if"datenum"
is specified ordatetime
format if"datetime"
is specified. By default the output is in serial date format.
Data Types: char
| string
Output Arguments
MATLAB date, returned as serial date numbers or adatetime
array.
The type of output is determined by an optionaloutputType
input argument. IfoutputType is "datenum"
, then MATLABDate
is a serial date number. IfoutputType
is "datetime"
, then MATLABDate
is a datetime
array. By default, outputType
is"datenum"
.
Version History
Introduced before R2006a
There are no plans to remove x2mdate
. However, thedatetime function is recommended instead because it returns datetime
values. Thedatetime
data type provides flexible date and time formats, storage out to nanosecond precision, and properties to account for time zones and daylight saving time.
To convert an Excel serial date number to a datetime
value, call the datetime
function with the "excel"
input argument.
excelNum = 44481 dt = datetime(excelNum,"ConvertFrom","excel")
Previously, x2mdate
required Financial Toolbox™.