Documentation

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 arrayX.

  • IfXis a numeric array, thenDis acalendarDurationarray with each element equal to the number of calendar days in the corresponding element ofX. Calendar days account for Daylight Saving Time shifts when used in calendar calculations.

  • IfXis acalendarDurationarray, thenDis adoublearray with each element equal to the number of whole calendar days in the corresponding element ofX.

Examples

collapse all

X = magic(5); D = caldays(X)
D =5×5 calendarDuration array17d 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 =1×3 calendarDuration array8d 1h 14m 4.2s 9d 1h 14m 4.2s 10d 1h 14m 4.2s
D = caldays(X)
D =8 9 10

caldaysreturns a numeric array.

添加两个日历天current date and time.

t = datetime('now') + caldays(2)
t =datetime26-Feb-2017 12:31:17

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

T = datetime([2014,03,18]) + caldays(0:4)
T =1×5 datetime array18-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 =1×5 datetime array18-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. IfXis a numeric array, it must contain only integer values. That is, you cannot create fractional calendar units.

Tips

  • caldayscreates days that account for Daylight Saving Time shifts when used in calendar calculations. To create exact fixed-length (24 hour) days, use thedaysfunction.

Extended Capabilities

Introduced in R2014b

Was this topic helpful?