week - Week number of input date and time - MATLAB (original) (raw)
Week number of input date and time
Syntax
Description
w = week([t](#buf%5F4ov-1%5Fsep%5Fshared-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.
w = week([t](#buf%5F4ov-1%5Fsep%5Fshared-t),[weekType](#buf%5F4ov-1-weekType))
returns week numbers of the type specified by weekType
.
Examples
t = datetime(2013,05,31):calmonths(3):datetime(2014,06,15)
t = 1×5 datetime 31-May-2013 31-Aug-2013 30-Nov-2013 28-Feb-2014 31-May-2014
Input Arguments
Input date and time, specified as a datetime
array.
Type of week values, specified as a value in the table.
Value ofweekType | 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
Theweek
function fully supports tall arrays. For more information, see Tall Arrays.
Version History
Introduced in R2014b
To return the ISO week-of-year number, use the 'iso-weekofyear'
option. In the ISO 8601 standard, every week starts on a Monday. Week 1 of a year is defined as the first week in the year with at least four days.
To return a consistent week-of-month number, use the'iso-weekofmonth'
option. 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.