(Not recommended; use
week) Week in year
weeknum is not recommended. Use the
function instead because it accepts
datetime values as inputs. For
more information on updating your code, see Version History or Replace Discouraged Instances of Serial Date Numbers and Date Strings.
Determine the Week of the Year
Determine the week of the year using a serial date number.
N = weeknum(728647)
N = 52
Determine the week of the year using a string.
N = weeknum("19-Dec-1994")
N = 52
Determine the week of the year using a
N = weeknum(datetime("19-Dec-1994","Locale","en_US"))
N = 52
The first week of the year must have at least four days in it. For example, January 8, 2004 was a Thursday. The European standard is used because the first week of the year is the first week longer than three days.
ans = 1
You can also use
ans = 1×8 1 1 1 2 2 2 2 2
The default start day of the week is Sunday. Every day after, and including the first Sunday of the year (04-Jan-2004), returns
2 denoting the second week. In this case, the first of week of the year started before January 1, 2004. You can also use
datenum and specify a
D value of
5 to indicate that the weeks start on Thursday.
ans = 1×8 1 1 1 1 1 1 1 2
The first week of the year that has four or more days, based on the specified start day, is considered week one (even if this is not the first week in the calendar). Any day falling in (or before) this week is given a week number of 1.
D — Date to determine week in year
serial date number | date string |
Date to determine week in year, specified as a serial date number, date
Serial date numbers can be a matrix. Date strings can be specified as a string vector or a one-dimensional cell array of character vectors. All the date strings must have the same format.
W — Day a week begins
(default) | integer with value
7 | vector of integers with values
Day a week begins, specified as an integer or a vector of integers from
1— Sunday (default)
weeknum function considers the week
containing January 1 to be the first week of the year.
E — Flag indicates if week of year display is European standard
(default) | numeric with values
Flag indicates if week of year display is European standard, specified as
1 (to use the European standard) or
0 (not to use the European standard).
The European standard considers first week of year to be first week longer than three days, offset by the given week’s start day.
N — Week number of the year, given
numeric | column vector
Week number of the year, given
D, returned as a
numeric value, given
D, a serial date number, date
datetime array. If
D is a
string vector or a one-dimensional cell array of character vectors, then
weeknum returns a column vector of
M week numbers, where M is the
number of elements in
Version HistoryIntroduced before R2006a
R2022a: Not recommended
There are no plans to remove
weeknum. However, the
week function is recommended
instead because it accepts
datetime values as inputs. The
datetime data type provides flexible date and time formats,
storage out to nanosecond precision, and properties to account for time zones and
daylight saving time.
To return the week in the year, call
week with the
"weekofyear" argument. If
dt is a
datetime value, then this
returns the week of the year for
dt = datetime("today") weekNumber = week(dt,"weekofyear")
R2022a: Moved to MATLAB from Financial Toolbox
weeknum required Financial Toolbox™.