[英]Excel how to convert weeknum to date when crossing the year
I have a table with Date column and weeknum column.我有一个包含 Date 列和 weeknum 列的表。
The weeknum column has below formula to create a srting: 2022/10. weeknum 列具有以下公式来创建 srting:2022/10。
=YEAR([@[Date]})&"/"&WEEKNUM([@[Date]],2)
I would like to get the start day and end day of the week converting from the string "2022/10".我想从字符串“2022/10”转换为一周的开始日和结束日。
I tried =DATE($M$1,1,-2)-(WEEKDAY(DATE($M$1,1,3))+(MID(M4,6,2)*7))
where $M$1
references current year and M4
references Year/ weeknum but it returns 10/17/2021.我试过
=DATE($M$1,1,-2)-(WEEKDAY(DATE($M$1,1,3))+(MID(M4,6,2)*7))
其中$M$1
引用当年M4
引用 Year/weeknum 但它返回 10/17/2021。 It should return 2/28/2022, and as the weeknumber increases.它应该返回 2/28/2022,并且随着周数的增加。 the returned dates decrease.
返回日期减少。 The dates of 2021/53 are correct, but the others got wrong.
2021/53 的日期是正确的,但其他日期错了。
How do I get fixed the dates?我如何确定日期?
You can do this by taking the weekday number of the date away from itself and adding 7-weekday to itself.您可以通过将日期的工作日编号从自身中取出并将 7-weekday 添加到自身来实现。
ie IE
If we use the first date on your list and we say weeks start on Monday:如果我们使用您列表中的第一个日期,并且我们说周从星期一开始:
The first day of the week (Monday) = E2-WEEKDAY(E2,2)+1 = 12/27/21一周的第一天(星期一) = E2-WEEKDAY(E2,2)+1 = 12/27/21
The last day of the week (Sunday) = E2+(7-WEEKDAY(E2,2)) = 01/02/22一周的最后一天(星期日) = E2+(7-WEEKDAY(E2,2)) = 01/02/22
Note: I have assumed your first date (12/27/2021) is in Cell E2注意:我假设您的第一次约会 (12/27/2021) 在单元格 E2 中
If you want Sunday to be the first day of the week, simply add a 1 instead of a 2 into the WEEKDAY part of the formula.如果您希望星期日成为一周的第一天,只需在公式的 WEEKDAY 部分添加 1 而不是 2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.