简体   繁体   English

生成开始日期、结束日期和周数属于给定的开始和结束日期

[英]Generate start date, end date and week numbers belong to given start and end date

I want generate week no list and start date and end date for particular week by giving some date range and I did as using below formaula.But I want consider all dates after belong to week 52 as week 1.my formulas working well if start and end dates belong to same year.But if I select start date after 26th dec like my formulas doesnt work.Please help.I consider monday to sunday.If I select dec29 it shows incorrect data(red highlighted) A1-Start date(this is giving by calender picker) B1-End Date((this is giving by calender picker)我想通过给出一些日期范围来生成特定周的无列表和开始日期和结束日期,我使用下面的公式做了。但我想将属于第 52 周之后的所有日期视为第 1 周。如果开始和结束日期属于同一年。但是如果我 select 开始日期在 12 月 26 日之后像我的公式不起作用。请帮助。我考虑周一到周日。如果我 select dec29 它显示不正确的数据(红色突出显示)A1-开始日期(这是通过日历选择器给予)B1-结束日期((这是由日历选择器给予)

A3 =IF(A1="","",YEAR(A1))

B3 =IF($A$1-WEEKDAY($A$1,3) +((ROW()-3)*7) <= $B$1-WEEKDAY($B$1,3), ISOWEEKNUM($A$1-WEEKDAY($A$1,3)+((ROW()-3)*7)), "")

C3 =IF(DATE(YEAR(B1),MONTH(B1),DAY(B1))>=DATE(YEAR(A1),MONTH(A1),DAY(A1)),IF(A1<>"",A1,""),"CHECK DATE RANGE")

D3=IF(DATE(YEAR(B1),MONTH(B1),DAY(B1))>=DATE(YEAR(A1),MONTH(A1),DAY(A1)),IF(B1<>"",MIN(DATE(A3+1,1,2),(DATE(A3,1,1)-WEEKDAY(DATE(A3,1,1),2)+B3*7)),""),"CHECK DATE RANGE")

图片

I Want result as below我想要结果如下

图 2

These formulas will work in Row 3:这些公式适用于第 3 行:

A3  =IF(ISNUMBER($A$1),YEAR(A1),"")
B3  =IF(ISNUMBER($A$1),WEEKNUM($A$1,2),"")
C3  =IF(ISNUMBER($A$1),$A$1-WEEKDAY($A$1,2)+1,"")
D3  =IF(ISNUMBER($A$1),$A$1+6-WEEKDAY($A$1,2)+1,"")

Starting in Row 4, enter these formulas, then use the auto-fill cursor (select cells A4:D4, then click and hold on the lower-right corner icon of the selection box) to copy-fill as many rows down as you need.从第 4 行开始,输入这些公式,然后使用自动填充 cursor(选择单元格 A4:D4,然后单击并按住选择框的右下角图标)复制填充所需的行数.

A4  =IF(ISNUMBER($D3),IF(($D3+1)<$B$1,YEAR($D3),""),"")
B4  =IF(ISNUMBER($D3),IF(($D3+1)<$B$1,WEEKNUM($D3,2),""),"")
C4  =IF(ISNUMBER($D3), IF( ($D3+1)<$B$1,  $D3+1,""),"")
D4  =IF(ISNUMBER($C4),$C4+6,"")

By the way, you mentioned in your post that you wanted Monday as the start of the week.顺便说一句,您在帖子中提到您希望星期一作为一周的开始。 So I used the value 2 in both WEEKNUM and WEEKDAY .所以我在WEEKNUMWEEKDAY中都使用了值2 Use a different value for other days if needed.如果需要,对其他日期使用不同的值

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

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