Reversed weeknumber function?

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
919
Office Version
  1. 365
Platform
  1. Windows
I have like this:
Source Date: December 31st, 2020
Result: 53/2020
Formula: WEEKNUM(A1;21)&"/"&YEAR(A1)

But how about the same backwards, what would you suggest? The exact date would preferably be the particular Monday.

So input: 53/2020 (which can be parsed obviously to 53 and 2020 with a split at the slash)
should somehow calculate 44193 (which is December 28th 2020).

I was thinking of making simply a large lookup table, but I have a feeling that's unnecessary.

Oh and I need to do this without VBA, just by using Excel functions.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I have not done comprehensive testing on this but it works on your example. Please check to see if this works for your other data. The "ww/yyyy" value is in B1 for this example.
Excel Formula:
=7-WEEKDAY(VALUE(RIGHT(B1,4)),12)+7*(LEFT(B1,FIND("/",B1)-1)-2)+DATE(RIGHT(B1,4),1,1)
 
Upvote 0
I have not done comprehensive testing on this but it works on your example. Please check to see if this works for your other data. The "ww/yyyy" value is in B1 for this example.
Excel Formula:
=7-WEEKDAY(VALUE(RIGHT(B1,4)),12)+7*(LEFT(B1,FIND("/",B1)-1)-2)+DATE(RIGHT(B1,4),1,1)
I think that's a very good start. I noticed that 1/2021 returns December 29th, but the correct result would be something between January 4th and January 10th.
 
Upvote 0
I think this works:

Excel Formula:
=LET(
y, B3,
week,C3,
firstDayOfYear, DATE(y,1,1),
firstWeek, SEQUENCE(7,,firstDayOfYear-5),
firstWeeksMonday, MAX(firstWeek*(WEEKDAY(firstWeek,2)=1)),
firstWeeksMonday+7*(week-1)
)

I'm starting with year and week in different columna. I'm missing the parsin, but that is an easy fix.

1705119794542.png


I think it works ok. For the first week of the year it does not match with WEEKNUM for every year, but that is ok. Because you are returning the monday of the first week of the year.
For example if you have the start of the year 2013. The week of 2013 where WEEKNUM returns 1 for the first time start with sunday 30/12/2012 (week in red text). So the monday of that week is 31/12/2012 which is (I think) the correct answer, because in this week we have the first day of the year, 1/1/2013. Dunno if that makes sense. It did to me.

1705119233590.png


Try it for other years/weeks and let me know.
 
Upvote 0
Here is another option. It may need to be adjusted, depending on the system used (assuming Week 1 is the week containing January 1) and weeks begin on Sunday. Inputs need by formula in blue, output in green. I left some formulas in the sheet to show what certain parts of the formula are doing. EDIT: Based on your comment about 1/2021 ideally returning something between January 4 and January 10, I'm guessing that a different "Week 1" convention is desired (other than Week is the week containing January 1)?
MrExcel_20240112.xlsx
ABCD
1Input Date12/31/202012/16/20184/18/2013
2Fwd conversion53/202051/201816/2013
3Parse weeknum535116
4Parse year202020182013
51st Sunday of year1/5/20201/7/20181/6/2013
61st Monday of year1/6/20201/1/20181/7/2013
7Monday of Weeknum12/28/202012/17/20184/15/2013
Sheet3
Cell Formulas
RangeFormula
B2:D2B2=WEEKNUM(B1,1)&"/"&YEAR(B1)
B3:D3B3=LEFT(B2,FIND("/",B2)-1)+0
B4:D4B4=RIGHT(B2,4)+0
B5:D5B5=DATE(B4,1,8)-WEEKDAY(DATE(B4,1,7))
B6:D6B6=DATE(B4,1,8)-WEEKDAY(DATE(B4,1,6))
B7:D7B7=IF(DATE(B4,1,8)-WEEKDAY(DATE(B4,1,6))>DATE(B4,1,8)-WEEKDAY(DATE(B4,1,7)),B3-2,B3-1)*7+DATE(B4,1,8)-WEEKDAY(DATE(B4,1,6))
 
Last edited:
Upvote 0
I have like this:
Source Date: December 31st, 2020
Result: 53/2020
Formula: WEEKNUM(A1;21)&"/"&YEAR(A1)

But how about the same backwards, what would you suggest? The exact date would preferably be the particular Monday.

So input: 53/2020 (which can be parsed obviously to 53 and 2020 with a split at the slash)
should somehow calculate 44193 (which is December 28th 2020).

I was thinking of making simply a large lookup table, but I have a feeling that's unnecessary.

Oh and I need to do this without VBA, just by using Excel functions.
Hi Jaymond,

Am I reading you correctly that you wish to ENTER '53/2020' into a cell and then have that entry converted into a 'Monday DATE' for WEEK 53, YEAR 2020?

Just curious, thanks.
 
Upvote 0
A little shorter version of the formula:

Excel Formula:
=LET(
y, B3,
week,C3,
firstDayOfYear, DATE(y,1,1),
firstWeeksMonday, WORKDAY.INTL(firstDayOfYear+2,-1,"0111111"),
firstWeeksMonday+7*(week-1)
)
 
Upvote 0
@felixstraube, unless the OP hasn't updated their profile, it appears as though Excel 2016 is being used...so the Excel 365 LET function may not, unfortunately, be available. Still, the inner parts of the function would work fine.
 
Upvote 0
A little shorter version of the formula:

Excel Formula:
=LET(
y, B3,
week,C3,
firstDayOfYear, DATE(y,1,1),
firstWeeksMonday, WORKDAY.INTL(firstDayOfYear+2,-1,"0111111"),
firstWeeksMonday+7*(week-1)
)
Hi Felix,

Not to step on your toes, but I realize now that what OP is looking for is to REVERSE his INPUT and OUTPUT process. I though at first when OP stated "backwards", it meant instead of current output of WW/YYYY to be YYYY/WW.

1705121733760.png

This is way above my paygrade... but I wanted to share a shorter formula I found that produces the same results as yours that I think you may like. I found it on ablebits.
Excel Formula:
=DATE(B2, 1, -2) - WEEKDAY(DATE(B2, 1, 3)) + A2 * 7
1705121762128.png

Best regards,
 
Upvote 0
Hi Jaymond,

Am I reading you correctly that you wish to ENTER '53/2020' into a cell and then have that entry converted into a 'Monday DATE' for WEEK 53, YEAR 2020?

Just curious, thanks.
Input parameter would be 53/2020 string and output would be the date of the Monday of the week 53 of 2020.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top