This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Duration in days


D = days(X)



D = days(X) returns an array of days equivalent to the values in X.

  • If X is a numeric array, then D is a duration array in units of fixed-length days. A fixed-length day is equal to 24 hours.

  • If X is a duration array, then D is a double array with each element equal to the number of fixed-length (24-hour) days in the corresponding element of X.

The days function converts between duration and double values. To display a duration in units of days, set its Format property to 'd'.


collapse all

X = magic(2);
D = days(X)
D = 2x2 duration array
    1 day   3 days
   4 days   2 days

Add each number of fixed-length days to the current date and time.

t = datetime('now') + D
t = 2x2 datetime array
   14-Apr-2019 00:06:17   16-Apr-2019 00:06:17
   17-Apr-2019 00:06:17   15-Apr-2019 00:06:17

Create a duration array.

X = hours(23:20:95) + minutes(45)
X = 1x4 duration array
   23.75 hr   43.75 hr   63.75 hr   83.75 hr

Convert each duration in X to a number of days.

D = days(X)
D = 1×4

    0.9896    1.8229    2.6562    3.4896

Input Arguments

collapse all

Input array, specified as a numeric array, duration array, or logical array.


  • days creates fixed-length (24 hour) days. To create days that account for Daylight Saving Time shifts when used in calendar calculations, use the caldays function.

Extended Capabilities

See Also


Introduced in R2014b