Main Content

calweeks

Calendar duration in weeks

Description

The calweeks function returns an array that represents calendar weeks. When you use arrays that have the calendarDuration data type in calendar calculations, the calculations take into account leap years, Daylight Saving Time shifts, and the differing lengths of calendar months. For calculations that involve fixed lengths of time, use the duration data type.

W = calweeks(X) returns an array representing calendar weeks equivalent to the values in X.

  • If X is a numeric array, then W is a calendarDuration array with each element equal to the number of calendar weeks in the corresponding element of X.

  • If X is a calendarDuration array, then calweeks returns the number of whole weeks equivalent to each calendar duration in X.

example

Examples

collapse all

X = magic(4);
W = calweeks(X)
W = 4x4 calendarDuration
   16w    2w    3w   13w
    5w   11w   10w    8w
    9w    7w    6w   12w
    4w   14w   15w    1w

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

X = caldays(15:17) + hours(1.2345)
X = 1x3 calendarDuration
   15d 1h 14m 4.2s   16d 1h 14m 4.2s   17d 1h 14m 4.2s

W = calweeks(X)
W = 1×3

     2     2     2

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.

Output Arguments

collapse all

Calendar weeks, returned as a scalar, vector, matrix, or multidimensional array. W is the same size as X. The data type of W depends on X.

  • If X is a numeric array, then W is an array of calendar durations in units of equivalent flexible-length calendar weeks.

  • If X is a calendarDuration array, then W is a double array of integer values representing whole calendar weeks.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2014b