Main Content

week

Week number of input date and time

Description

w = week(t) returns the week number for each date and time in the input array. By default, week returns week-of-year numbers. The output w is a double array that has the same size as t and contains integer values from 1 to 53.

example

w = week(t,weekType) returns week numbers of the type specified by weekType.

Examples

collapse all

t = datetime(2013,05,31):calmonths(3):datetime(2014,06,15)
t = 1x5 datetime
   31-May-2013   31-Aug-2013   30-Nov-2013   28-Feb-2014   31-May-2014

w = week(t)
w = 1×5

    22    35    48     9    22

Input Arguments

collapse all

Input date and time, specified as a datetime array.

Type of week values, specified as a value in the table.

Value of weekType

Description

'weekofyear' (default)

Week-of-year number, from 1 to 53. Week 1 of the year starts on January 1st, with every following week of the year starting on a Sunday. In most years, weeks 1 and 53 contain fewer than seven days and do not extend from Sunday to Saturday.

'weekofmonth'

Week-of-month number, from 1 to 5. Week 1 of the month starts on the first day of the month, with every following week of the month starting on a Sunday. In most months, the first and last weeks contain fewer than seven days and do not extend from Sunday to Saturday.

'iso-weekofyear' (since R2023a)

Week-of-year number, from 1 to 53, according to the ISO 8601 standard. Every week contains seven days, starting on a Monday and ending on the following Sunday. Week 1 of a year is defined as the first week in the year with at least four days. In most years, weeks 1 and 53 extend into the previous and next year respectively.

'iso-weekofmonth' (since R2023a)

Week-of-month number, from 1 to 5, calculated in a way that is consistent with the ISO 8601 standard. Every week contains seven days, starting on a Monday and ending on the following Sunday. Week 1 of a month is defined as the first week in the month with at least four days. In most months, the first and last weeks extend into the previous and next month respectively.

Note: ISO 8601 does not specifically define the week-of-month number. However, this option returns a week-of-month number that is consistent with the ISO week-of-year number.

Extended Capabilities

Version History

Introduced in R2014b

expand all

See Also

| | |