week
Week number of input date and time
Description
w = week(
returns the week number for
each date and time in the input array. By default, t
)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.
Examples
Find Week of Year Numbers of Dates
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
t
— Input date and time
datetime
array
Input date and time, specified as a datetime
array.
weekType
— Type of week values
'weekofyear'
(default) | 'weekofmonth'
| 'iso-weekofyear'
| 'iso-weekofmonth'
Type of week values, specified as a value in the table.
Value of
| Description |
---|---|
| 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. |
| 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. |
| 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. |
| 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
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
The
week
function fully supports tall arrays. For more information,
see Tall Arrays.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2014bR2023a: Return ISO week of year or week of month
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.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)