简体   繁体   中英

Get date from week number in Google Sheets

If I have week 7 in 2017 what week date is the Monday in that week in Google Sheets?

=DATE(B9,1,1)-WEEKDAY(DATE(B9,1,1),3)+7*(WEEKDAY(DATE(B9,1,1),3)>3)+7*(A9-1)

是最复杂的公式,我知道这对于瑞典周数有效(即Monday first day of weekISO的规则对于什么是一周1 )。

Short answer (A1==Week, B1==Year):

=DATE(B1;1;1)+((A1-1)*7)-WEEKDAY(DATE(B1;1;1);3)

Long answer:

DATE(<year>;1;1) // days since 1970 until the frist day of the year

plus

((<week number>-1)*7) // how many days into the year is this week

minus

WEEKDAY(DATE(<year>;1;1);3) // how many extra days from previous year in first week

PS:

This assumes monday as the first day of week you have to change the arguments for WEEKDAY to change it to sunday

Because of this definition ( https://en.wikipedia.org/wiki/Week ) the 4th of January must be used instead the 1st. The 4th of January is the first day which is always in the week 1.

=DATE(B1;1;4)+((A1-1)*7)-WEEKDAY(DATE(B1;1;4);3)

If you are using ISO weeks, the accepted answer doesn't account for weeks overlapping on 2 technical years like 2020-w53 , which is from 28 Dec 2020 until 3 Jan 2021.

Therefore I'm using this formula instead:

=DATE(K2,1,1)-WEEKDAY(DATE(K2,1,1),2)+7*(WEEKDAY(DATE(K2,1,1),2)>3)+7*(L2-1) +1

Where K is the Year, and L is the Week number (split in 2 columns from yyyy-ww)

to have it in an arrayformula:

=ArrayFormula(if(K2:K="",, DATE(K2:K,1,1)-WEEKDAY(DATE(K2:K,1,1),2)+7*(WEEKDAY(DATE(K2:K,1,1),2)>3)+7*(L2:L-1) +1 ))

You can use =ArrayFormula(if(E2:E="",,split(E2:E,"-"))) to split yyyy-ww in two columns.

NOTE: This formula would return the Monday (Which is the first day of the week in international standard, ISO)

Worked this up for 2023. It will work through end of 2024 too.. that said the AND logic is flawed.. feel free to suggest something to make this better

=IFS(
AND(ISOWEEKNUM(A8)=52,YEAR(A8)<>YEAR(A7)),

DATE(YEAR(A8-1),1,1)-WEEKDAY(DATE(YEAR(A8-1),1,1),3)+7*(WEEKDAY(DATE(YEAR(A8-1),1,1),3)>3)+7*(ISOWEEKNUM(A8)-1),

DATE(YEAR(A8),1,1)-WEEKDAY(DATE(YEAR(A8),1,1),3)+7*(WEEKDAY(DATE(YEAR(A8),1,1),3)>3)+7*(ISOWEEKNUM(A8)-1)
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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