m2xdate

MATLAB serial date number to Excel serial date number

Syntax

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

Arguments

 `MATLABDateNumber` A vector or scalar of MATLAB® serial date numbers. `Convention` (Optional) Excel® date system. A vector or scalar. 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```

Vector arguments must have consistent dimensions.

Description

`DateNum = m2xdate(MATLABDateNumber, Convention)` converts MATLAB serial date numbers 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™ EX software.

Examples

collapse all

Convert MATLAB Serial Date Numbers Using 1900 Date System

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 = 37250 37615 37980 38346 ```

Convert MATLAB Serial Date Numbers Using 1904 Date System

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 = 35788 36153 36518 36884 ```