convertTo

Converts datetime values to a numeric date representation.

Category: Language Fundamentals > Data Types

Syntax

d = convertTo(t, type)

Converts the datetime array t to the numeric format type.

Description

Each format counts time from its own origin: 'datenum' from year 0, 'posixtime' in seconds since 1970-01-01, 'excel' in days since 1900, and 'yyyymmdd' packs year, month and day into one integer such as 20200101. The inverse is datetime(d, 'ConvertFrom', type).

Input arguments

t
datetime array.
type
Text: 'datenum', 'posixtime', 'excel', 'juliandate', 'yyyymmdd', and others.

Output arguments

d
Numeric array with the size of t.

Example

Several numeric formats

t = datetime(2020,1,1);
convertTo(t, 'datenum')
convertTo(t, 'excel')
convertTo(t, 'yyyymmdd')
Output
ans = 737791
ans = 43831
ans = 20200101

See also

datetime datenum posixtime datestr