weeknum
Week of the year in which a date falls.
Category: Language Fundamentals > Data Types
Syntax
n = weeknum(d)
Returns the week number of each serial date number d, with weeks starting on Sunday.
n = weeknum(d, w)
Chooses the first day of the week: w is 1 for Sunday (default) or 2 for Monday.
Description
Week 1 is the week that contains January 1. The year is cut into consecutive blocks of seven days that begin on the chosen weekday, so the last days of December can already belong to week 53 or week 1 of the next year, depending on the convention.
This is a simple calendar count, not the ISO 8601 week number.
Input arguments
d- Date as a serial date number, as produced by
datenum. w- Week convention: 1 starts the week on Sunday, 2 on Monday.
Output arguments
n- Week numbers, an integer from 1 to 53 for each date.
Example
Last and first day of 2024
d = datenum(2024, 12, 31);
weeknum(d)
weeknum(datenum(2024, 1, 1))
Output
ans = 53
ans = 1