# m2xdate

MATLAB date to Excel serial date number

## Syntax

``DateNum = m2xdate(MATLABDateNumber,Convention)``

## Description

example

````DateNum = m2xdate(MATLABDateNumber,Convention)` converts MATLAB® serial date numbers, date character vectors, or datetime arrays to Excel® serial date numbers. MATLAB date numbers start with `1` = January 1, 0000 A.D., 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.```

## Examples

collapse all

This example shows how to convert MATLAB serial date numbers using the 1900 date system. Given MATLAB date numbers for Christmas 2001 through 2004, convert them to Excel date numbers in the 1900 system.

```DateNum = datenum(2001:2004, 12, 25); ExDate = m2xdate(DateNum)```
```ExDate = 1×4 37250 37615 37980 38346 ```

This example shows how to convert MATLAB® date numbers using a datetime array with the 1900 date system. Given MATLAB date numbers for Christmas 2001 through 2004, convert them to Excel date numbers in the 1904 system.

```DateNum = datetime(2001:2004, 12, 25,'Locale','en_US'); ExDate = m2xdate(DateNum)```
```ExDate = 1×4 37250 37615 37980 38346 ```

This example shows how to convert MATLAB serial date numbers using the 1904 date system. Given MATLAB date numbers for Christmas 2001 through 2004, convert them to Excel date numbers in the 1904 system.

```DateNum = datenum(2001:2004, 12, 25); ExDate = m2xdate(DateNum, 1)```
```ExDate = 1×4 35788 36153 36518 36884 ```

## Input Arguments

collapse all

MATLAB dates, specified as a scalar or vector of MATLAB serial date numbers, date character vectors, or datetime arrays.

Data Types: `double` | `char` | `datetime`

Flag for Excel date system, specified as a scalar or vector as a numeric with a value `0 `or `1`.

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 DATEVALUE's 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`
```ans = 2```

Data Types: `logical`

## Output Arguments

collapse all

Excel serial date number, returned as an array of serial date numbers in Excel serial date number form.