Return the week number of the year of a date
d is a serial date number or datestring.
w is (optionally) the day that defines the first day of the week (1 is Sunday, 2 is Monday etc.). Default is 1 (Sunday).
e is a boolean to toggle the "European" definition that the first week should contain at least 4 days of the new year. (And hence always contains 4th of January). Default is 0, in which case the first week of the year is the week that contains the first day of the year.
Please note that when e is zero, days in a week that overlap two years do not all return the same weeknumber.
y will be the year in which the week falls. When e=0 (default) y will always be the year of the input date. When e=1, the week may be in the next or previous year.
Note: In ISO8601 weeks start with Monday. The first week of a year
is the week that contains at least 4 days (and hence contains the first
Thursday of the year and also always contains the 4th of January).
So for an ISO8601 weeknumber use: n = weeknum (d, 2, 1)
.
See also: datenum, datestr.
The following code
d = datenum (2014, 12, 29); [w, y] = weeknum (datenum (2014, 12, 29), 2, 1); disp(['In ISO8601 ' datestr(d) ' is week ' num2str(w) ' of year ' num2str(y)]) disp(['Octave default weeknumber for ' datestr(d) ' is ' num2str(weeknum (d))])
Produces the following output
In ISO8601 29-Dec-2014 is week 1 of year 2015 Octave default weeknumber for 29-Dec-2014 is 53
Package: financial