Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel weeknum function returns wrong week

Tags:

excel

Question is as in title.

I have a cell, "D4", with the date "09/07/2016" in it. Adjacent cell has formula "=weeknum(D4,1)". The output of this function is "28". But on a Sunday-Saturday basis, Saturday the 9th of July wasn't in week 28 - it was in week 27.

I thought this might be something to do with Saturday/Sunday and when the week starts and finishes, etc, so I tried multiple different dates from last week - Monday the 4th, Tuesday the 5th, Wednesday the 6th, etc. In each case, "weeknum" returns a value of "28".

I only noticed the problem because I have a macro which uses the value of the cell with the week number to look for a spreadsheet saved by our accounts team on a weekly basis. As they have - correctly - saved the spreadsheet as "week 27", it didn't work. I initially assumed that the accounts team were wrong, but I checked online and they are correct.

How could this happen? Surely Excel can't be wrong and I must have made a mistake of some sort?

I know that there is an issue with Excel not following ISO standards for when weeks 53 and 1 begin and end, but I don't see how that could affect a mid-year week.

It did occur to me that the issue might be to do with UK versus US date formatting. But, of course, the 7th of June wasn't in week 28 either.

like image 878
Statsanalyst Avatar asked Jul 14 '16 14:07

Statsanalyst


People also ask

How do you reset the week number in Excel?

Using the WEEKDAY() function to reset the week number to 1 every time the first Monday of the next month is reached.

What is the difference between ISOWeekNum and Weeknum in Excel?

WeekNum uses the week containing January 1 as the first week of the year. The result from this function can range from 1 to 54. ISOWeekNum uses the week containing the first Thursday of the year as the first week of the year. This follows the ISO 8601 date and time standard definition for week numbering.

How does Weeknum in Excel Work?

Returns the week number of a specific date. For example, the week containing January 1 is the first week of the year, and is numbered week 1. There are two systems used for this function: System 1 The week containing January 1 is the first week of the year, and is numbered week 1.


2 Answers

That all is documented in WEEKNUM.

There are two systems used for this function:

System 1 The week containing January 1 is the first week of the year, and is numbered week 1.

System 2 The week containing the first Thursday of the year is the first week of the year, and is numbered as week 1. This system is the methodology specified in ISO 8601, which is commonly known as the European week numbering system.

Syntax

WEEKNUM(serial_number,[return_type])

Return_type  Week begins on  System 
...
21           Monday          2

So =WEEKNUM("09/07/2016",21) will calculate as defined in ISO 8601 since Return_type 21 is the only one with System 2.


ISOWEEKNUM

=ISOWEEKNUM("09/07/2016")

will also do it.

like image 183
Axel Richter Avatar answered Sep 23 '22 13:09

Axel Richter


=ISOWEEKNUM(a2)-1 returns the correct week for me, the same as =WEEKNUM(a2,21)-1

like image 25
wobba Avatar answered Sep 23 '22 13:09

wobba