Documentation

### This is machine translation

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

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

# caldays

Calendar duration in days

## Syntax

``D = caldays(X)``

## Description

example

````D = caldays(X)` returns an array representing calendar days equivalent to the values in array `X`. If `X` is a numeric array, then `D` is a `calendarDuration` array with each element equal to the number of calendar days in the corresponding element of `X`. Calendar days account for Daylight Saving Time shifts when used in calendar calculations.If `X` is a `calendarDuration` array, then `D` is a `double` array with each element equal to the number of whole calendar days in the corresponding element of `X`. ```

## Examples

collapse all

```X = magic(5); D = caldays(X)```
```D = 5x5 calendarDuration array 17d 24d 1d 8d 15d 23d 5d 7d 14d 16d 4d 6d 13d 20d 22d 10d 12d 19d 21d 3d 11d 18d 25d 2d 9d ```

Create an array of calendar durations. Then, convert each value to the equivalent number of whole calendar days.

`X = caldays(8:10) + hours(1.2345)`
```X = 1x3 calendarDuration array 8d 1h 14m 4.2s 9d 1h 14m 4.2s 10d 1h 14m 4.2s ```
`D = caldays(X)`
```D = 1×3 8 9 10 ```

`caldays` returns a numeric array.

Add two calendar days to the current date and time.

`t = datetime('now') + caldays(2)`
```t = datetime 29-Aug-2018 13:34:20 ```

Create a sequence of consecutive dates beginning on March 18, 2014.

`T = datetime([2014,03,18]) + caldays(0:4)`
```T = 1x5 datetime array 18-Mar-2014 19-Mar-2014 20-Mar-2014 21-Mar-2014 22-Mar-2014 ```

Create a sequence of dates beginning on March 18, 2014, spaced 2 days apart.

`T = datetime([2014,03,18]) + caldays(0:2:8)`
```T = 1x5 datetime array 18-Mar-2014 20-Mar-2014 22-Mar-2014 24-Mar-2014 26-Mar-2014 ```

## Input Arguments

collapse all

Input array, specified as a numeric array, calendar duration array, or logical array. If `X` is a numeric array, it must contain only integer values. That is, you cannot create fractional calendar units.

## Tips

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