How to use the WEEKNUM function
What is the WEEKNUM function?
The WEEKNUM function calculates a given date's week number based on a return_type parameter that determines which day the week begins.
Table of Contents
1. Introduction
What is a week?
A week is a time unit used to represent the cycle of seven days in the Gregorian calendar. A week consists of seven consecutive days, typically beginning on Sunday, Monday or Saturday depending on country and calendar system.
Each week cycles through the seven days of the week - Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.
How many weeks in a year?
Week numbers range from 1 to 52 for most years. Some years have 53 weeks if the 1st week starts very early in the previous year.
Is a week the same in all parts of the world?
No, the definition and numbering of a week is not the same in all parts of the world.
There are some key differences:
- Start of week - Some calendars start the week on Sunday, others on Monday.
- Week numbering - The rules for when Week 1 begins in a year vary between calendars.
- ISO 8601 standard - This internationally recognizes Monday as start of week and has a consistent week numbering definition.
- Cultural variations - Some cultures or religions use different definitions of a week. For example, the Jewish calendar week starts on Sunday.
What is a week number?
A week number refers to the ordinal numbering of weeks in a calendar year.
ISO 8601 is the international standard for week numbering. Week numbers provide an alternative to the month/day system for identifying dates. They are commonly used in work/school calendars, schedules, timetables, payment periods, etc.
When does week numbers start?
Week 1 is the first week of the year that contains at least 4 days of the new year.
What is the difference between the WEKNUM function and the ISOWEEKNUM function?
ISOWEEKNUM follows the ISO 8601 international standard for week numbering, while WEEKNUM is based on a more localized definition.
ISOWEEKNUM always starts weeks on Monday and Week 1 is the first week with 4+ days in the new year. WEEKNUM can start weeks on Sunday or Monday based on system settings.
Region | First Day of Week | Week Numbering |
---|---|---|
Europe | Monday | ISO 8601 (Week 1 is first with 4+ days in new year) |
North America | Sunday | Other |
South America | Monday | ISO 8601 |
Asia | Monday or Sunday | Varies by country, ISO and others |
Middle East | Saturday | Varies by country |
Africa | Sunday or Monday | ISO 8601 or others |
Most regions follow ISO 8601 now but there are still some variations.
2. WEEKNUM function Syntax
WEEKNUM(serial_number,[return_type])
3. WEEKNUM function Arguments
serial_number | Required. A date. If you enter the date in the function then use the DATE function to calculate the correct serial_number. |
[return_type] | Optional. A number determining which day the week begins. If omitted, 1 is used. |
The following table shows how the WEEKNUM function defines a week if [return_type] argument is specified.
[return_type] | Week starts on | System |
1 | Sunday | 1 |
2 | Monday | 1 |
11 | Monday | 1 |
12 | Tuesday | 1 |
13 | Wednesday | 1 |
14 | Thursday | 1 |
15 | Friday | 1 |
16 | Saturday | 1 |
17 | Sunday | 1 |
21 | Monday | 2 |
You also have the option to choose which system to use, see the [return_type] argument.
System 1 | Week 1 is the week that contains January 1. |
System 2 | Week 1 is the week that contains the first Thursday of the year. (European week numbering system). |
4. WEEKNUM function example
Formula in cell D3:
5. Extract week ranges based on a given date range
The formula in cell B7 and C7 extracts whole weeks within the given date range in cell B3 and C3.
The following array formula in cell C7 extracts weeks that begin on a Sunday:
Formula in cell B7:
To enter an array formula, type the formula in a cell then press and hold CTRL + SHIFT simultaneously, now press Enter once. Release all keys.
The formula bar now shows the formula with a beginning and ending curly bracket telling you that you entered the formula successfully. Don't enter the curly brackets yourself.
Excel 365 dynamic array formula in cell B7:
Explaining formula in cell C7
Step 1 - Create array 1 to n
The INDEX function creates a cell reference with the same number of rows as there are dates in the date range.
The ROW function then converts the cell range to an array of corresponding row numbers.
ROW($A$1:INDEX($A$1:$A$1000, $C$3-$B$3))
becomes
ROW($A$1:INDEX($A$1:$A$1000, 40633-40569))
becomes
ROW($A$1:INDEX($A$1:$A$1000, 64))
becomes
ROW($A$1:$A$64)
and returns
{1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; 58; 59; 60; 61; 62; 63; 64}
Step 2 - Create dates within date range
The next step subtracts the array with 1 and adds the Excel date number.
$B$3+(ROW($A$1:INDEX($A$1:$A$1000, $C$3-$B$3))-1)
becomes
$B$3+({1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; 58; 59; 60; 61; 62; 63; 64}-1)
becomes
$B$3+{0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; 58; 59; 60; 61; 62; 63}
becomes
40569+{0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42; 43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; 58; 59; 60; 61; 62; 63}
and returns
{40569; 40570; 40571; 40572; 40573; 40574; 40575; 40576; 40577; 40578; 40579; 40580; 40581; 40582; 40583; 40584; 40585; 40586; 40587; 40588; 40589; 40590; 40591; 40592; 40593; 40594; 40595; 40596; 40597; 40598; 40599; 40600; 40601; 40602; 40603; 40604; 40605; 40606; 40607; 40608; 40609; 40610; 40611; 40612; 40613; 40614; 40615; 40616; 40617; 40618; 40619; 40620; 40621; 40622; 40623; 40624; 40625; 40626; 40627; 40628; 40629; 40630; 40631; 40632}
Step 3 - Convert dates to weekdays
The TEXT function converts the dates to weekdays.
TEXT($B$3+(ROW($A$1:INDEX($A$1:$A$1000, $C$3-$B$3))-1), "DDD")
becomes
TEXT({40569; 40570; 40571; 40572; 40573; 40574; 40575; 40576; 40577; 40578; 40579; 40580; 40581; 40582; 40583; 40584; 40585; 40586; 40587; 40588; 40589; 40590; 40591; 40592; 40593; 40594; 40595; 40596; 40597; 40598; 40599; 40600; 40601; 40602; 40603; 40604; 40605; 40606; 40607; 40608; 40609; 40610; 40611; 40612; 40613; 40614; 40615; 40616; 40617; 40618; 40619; 40620; 40621; 40622; 40623; 40624; 40625; 40626; 40627; 40628; 40629; 40630; 40631; 40632}, "DDD")
and returns
{"Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"}
Step 4 - Extract all Sundays
The IF function has three arguments, the first one must be a logical expression. If the expression evaluates to TRUE then one thing happens (argument 2) and if FALSE another thing happens (argument 3).
IF(TEXT($B$3+(ROW($A$1:INDEX($A$1:$A$1000, $C$3-$B$3))-1), "DDD")="Sat", $B$3+(ROW($A$1:INDEX($A$1:$A$1000, $C$3-$B$3))-1), "")
becomes
IF({"Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"; "Mon"; "Tue"; "Wed"}="Sun", $B$3+(ROW($A$1:INDEX($A$1:$A$1000, $C$3-$B$3))-1), "")
becomes
IF({FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; FALSE; FALSE}, {40569; 40570; 40571; 40572; 40573; 40574; 40575; 40576; 40577; 40578; 40579; 40580; 40581; 40582; 40583; 40584; 40585; 40586; 40587; 40588; 40589; 40590; 40591; 40592; 40593; 40594; 40595; 40596; 40597; 40598; 40599; 40600; 40601; 40602; 40603; 40604; 40605; 40606; 40607; 40608; 40609; 40610; 40611; 40612; 40613; 40614; 40615; 40616; 40617; 40618; 40619; 40620; 40621; 40622; 40623; 40624; 40625; 40626; 40627; 40628; 40629; 40630; 40631; 40632}, "")
and returns
{""; ""; ""; ""; 40573; ""; ""; ""; ""; ""; ""; 40580; ""; ""; ""; ""; ""; ""; 40587; ""; ""; ""; ""; ""; ""; 40594; ""; ""; ""; ""; ""; ""; 40601; ""; ""; ""; ""; ""; ""; 40608; ""; ""; ""; ""; ""; ""; 40615; ""; ""; ""; ""; ""; ""; 40622; ""; ""; ""; ""; ""; ""; 40629; ""; ""; ""}
Step 5 - Find n-th Sunday within range
To be able to return a new value in a cell each I use the SMALL function to filter date numbers from smallest to largest.
SMALL(IF(TEXT($B$3+(ROW($A$1:INDEX($A$1:$A$1000, $C$3-$B$3))-1), "DDD")="Sat", $B$3+(ROW($A$1:INDEX($A$1:$A$1000, $C$3-$B$3))-1), ""),ROWS($A$1:A2))
becomes
SMALL({""; ""; ""; ""; 40573; ""; ""; ""; ""; ""; ""; 40580; ""; ""; ""; ""; ""; ""; 40587; ""; ""; ""; ""; ""; ""; 40594; ""; ""; ""; ""; ""; ""; 40601; ""; ""; ""; ""; ""; ""; 40608; ""; ""; ""; ""; ""; ""; 40615; ""; ""; ""; ""; ""; ""; 40622; ""; ""; ""; ""; ""; ""; 40629; ""; ""; ""}),ROWS($A$1:A2))
becomes
SMALL({""; ""; ""; ""; 40573; ""; ""; ""; ""; ""; ""; 40580; ""; ""; ""; ""; ""; ""; 40587; ""; ""; ""; ""; ""; ""; 40594; ""; ""; ""; ""; ""; ""; 40601; ""; ""; ""; ""; ""; ""; 40608; ""; ""; ""; ""; ""; ""; 40615; ""; ""; ""; ""; ""; ""; 40622; ""; ""; ""; ""; ""; ""; 40629; ""; ""; ""}),2)
and returns 40580 formatted as 2/5/2011.
Step 6 - Return blank if error
The IFERROR function handles errors, it returns a specified value if formula returns an error. In this case it returns a blank "".
6. WEEKNUM function not working
The WEEKNUM function returns #NUM! error if:
- serial_number is out of range.
- [return_type] is out of range.
'WEEKNUM' function examples
This article describes how to count unique distinct values. What are unique distinct values? They are all values but duplicates are […]
Table of Contents How to use the NETWORKDAYS function How to use the NETWORKDAYS.INTL function How to use the NOW […]
The array formula in cell C2 extracts duplicate values from column A. Only one duplicate of each value is displayed […]
Functions in 'Date and Time' category
The WEEKNUM function function is one of 22 functions in the 'Date and Time' category.
Excel function categories
Excel categories
2 Responses to “How to use the WEEKNUM function”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form
Hi, Oscar
If B2=1-29-2011 then, your formula is not work.
Here's an alternative. It's not an array formula and shorter.
cell C2:
=IF($A2-WEEKDAY($A2,2)+7*COLUMN(A1)-$B2>=7,"", TEXT(MAX($A2,$A2-WEEKDAY($A2,2)+7*(COLUMN(A1)-1)+1), "m/d/yyyy") &" - "&TEXT(MIN($B2, $A2-WEEKDAY($A2,2)+7*COLUMN(A1)),"m/d/yyyy"))
aMareis,
I can´t find the file but thank you for commenting!