简体   繁体   English

Excel weeknum函数返回错误的星期

[英]Excel weeknum function returns wrong week

Question is as in title. 问题与标题相同。

I have a cell, "D4", with the date "09/07/2016" in it. 我有一个单元格“ D4”,日期为“ 09/07/2016”。 Adjacent cell has formula "=weeknum(D4,1)". 相邻单元格的公式为“ = weeknum(D4,1)”。 The output of this function is "28". 该功能的输出为“ 28”。 But on a Sunday-Saturday basis, Saturday the 9th of July wasn't in week 28 - it was in week 27. 但是从周日至周六的基础上,7月9日(星期六)不在第28周-而是在第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". 我认为这可能与周六/周日以及一周的开始和结束时间有关,所以我尝试了与上周不同的多个日期-周一4日,5日周二,6日周三等。在每种情况下, “ weeknum”返回值“ 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. 由于他们正确地将电子表格保存为“第27周”,因此无法正常工作。 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? 当然,Excel不会错,我一定犯了某种错误?

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. 我知道Excel在第53周和第1周的开始和结束时没有遵循ISO标准存在问题,但是我看不到这会对年中周产生怎样的影响。

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. 但是,当然,6月7日也不是在第28周。

That all is documented in WEEKNUM . 所有这些都记录在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. 系统1包含1月1日的一周是一年的第一周,并编号为第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. 系统2包含一年中第一个星期四的一周是一年中的第一周,并编号为第1周。此系统是ISO 8601中指定的方法,通常称为欧洲周编号系统。

Syntax 句法

WEEKNUM(serial_number,[return_type]) 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. 所以=WEEKNUM("09/07/2016",21)将按照ISO 8601的定义进行计算,因为Return_type 21是系统2中唯一的一个。


ISOWEEKNUM ISOWEEKNUM

=ISOWEEKNUM("09/07/2016")

will also do it. 也会做到的。

=ISOWEEKNUM(a2)-1为我返回正确的星期,与=WEEKNUM(a2,21)-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM