Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Create Date and Time Arrays

Create arrays to represent dates, time, and duration

The primary way to store date and time information is in datetime arrays, which support arithmetic, sorting, comparisons, plotting, and formatted display. The results of arithmetic computations are returned in duration arrays or, when you use calendar-based functions, in calendarDuration arrays. For more information, see Represent Dates and Times in MATLAB or watch Date and Time Arrays.

Functions

datetime Create array based on current date, or convert from date strings or numbers
timezones List time zones
years Duration in years
days Duration in days
hours Duration in hours
minutes Duration in minutes
seconds Duration in seconds
milliseconds Duration in milliseconds
duration Create duration array from numeric values
calyears Calendar duration in years
calquarters Calendar duration in quarters
calmonths Calendar duration in months
calweeks Calendar duration in weeks
caldays Calendar duration in days
calendarDuration Create calendar duration array from numeric values
exceltime Convert MATLAB datetime to Excel date number
juliandate Convert MATLAB datetime to Julian date
posixtime Convert MATLAB datetime to POSIX time
yyyymmdd Convert MATLAB datetime to YYYYMMDD numeric value

Properties

datetime Properties Assign date and time components and specify datetime display format

Topics

Represent Dates and Times in MATLAB

Use datetime arrays to store date and time information. These arrays support arithmetic, sorting, comparisons, plotting, and formatted display.

Set Date and Time Display Format

The Format property on datetime, duration, and calendarDuration arrays controls the display of values in each array. You can change the value of this property. Changing the Format property does not change the values in the array, only their display.

Specify Time Zones

When you create a datetime, it is unzoned by default. If you work with datetime values from multiple time zones or need to account for daylight saving time, you might need to specify a time zone.

Convert Date and Time to Julian Date or POSIX Time

You can convert datetime arrays to numeric formats that count seconds or days elapsed since the start time for a given format. When you convert a datetime array to POSIX times or Julian dates, the best practice is to specify the time zone before conversion.

Generate Sequence of Dates and Time

Generate sequences of dates and times. Sequences include dates and times that are consecutive, equally spaced between two points, or that use calendar rules.

Share Code and Data Across Locales

Follow these best practices when sharing code that handles dates and time with MATLAB® users in other locales. Write and read dates from other locals.

Was this topic helpful?