Convert year and ISO-week to date in Excel? - excel

The year is A1=2012
The ISO-week is A2=1
As I understand it the standard way to decide to which month a week belongs is to look at in which month the Thursday occurs.
Thus, I would like to find the date of the Thursday with year A1 and ISO week A2. How can I find the date of the Thursday?
I know that this thread is related, but I can't figure this out: calculate the month from the year and week number in excel

The Thursday of week 1 will always be the first Thursday of the year, then you obviously add 7 for each week after that, so you can get the Thursday date with this formula
=DATE(A1,1,1+A2*7)-WEEKDAY(DATE(A1,1,3))
with Year in A1 and ISO week number in A2

To find the date defined by (A1,B1,C1) where A1 = ISO Year, B1 = ISO Week, and C1 = the day of the week, assuming week starts with Monday, day 1, use the following:
In VBA:
S = DateSerial(A1, 1, 3)
W = Weekday(S)
D = S - W + 7 * B1 + C1 - 6
Or in one formula in Excel:
=DATE(A1,1,3) - WEEKDAY(DATE(A1,1,3)) + 7 * B1 + C1 - 6

Related

Formula based on first monday or tuesday etc of the week

Is there a way to put a year into a cell (say A1), then the day of the week you want (say Monday in cell A2) and enter into the 12 cells below it the first monday of each month (or first tuesday, etc, based on whats in cell A2)?
I have been able to figure out how to do it with 1 day but I would like it to be interactive.
=DATE(2022,{1;2;3;4;5;6;7;8;9;10;11;12},7-WEEKDAY(DATE(2022,{1;2;3;4;5;6;7;8;9;10;11;12},1)-5,3))
With Office 365:
=LET(yr,A1,
wkdy,MATCH(PROPER(A2),{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),
mnt,SEQUENCE(12),
DATE(yr,mnt,1)+MOD(8-WEEKDAY(DATE(yr,mnt,1),10+wkdy),7))
You where pretty close with your formula
=DATE(A1,{1;2;3;4;5;6;7;8;9;10;11;12},7)-WEEKDAY(DATE(A1,{1;2;3;4;5;6;7;8;9;10;11;12},7),A2)
Where
A1 = year string
A2 = day of the week as number (1 = Saturday, 2 = Sunday, etc.)

How to get week number of the month by week number of the year

I only have week number for the year. How can I get the week number of the month?
For ex:
Week
42
Week of the month
2
How can I get the “2” in excel?
I have created a formula for you.
=INT( DAY( (A1-1)*7+ (DATE(B1,1,1)+ (8-WEEKDAY(DATE(B1,1,1),2))) ) / 7)
The formula is inserted in C1, year is present in B1 and week number is present in A1
Week numbers are according to ISO stranded.

Calculate the week number of a given date using a given a reference year

I have a formula which calculates the week number of a given date:
=WEEKNUM(Sheet2!N83)
I want a formula which returns the week number using 2018 as reference, in a similar manner as the above formula does. If the year is 2019, I want it to return weeknum + 52, so for 2019-01-01 I get week number '53'.
How can I achieve this?
This is only valid for years 2018 and 2019:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(Sheet2!N83)+52)
or:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(DATE(2018,MONTH(Sheet2!N83),DAY(Sheet2!N83)))+52)
You actually need a formula which calculates the difference in weeks.
In A1 cell, fill the first day of the reference year (e.g. 2018-01-01).
In A2 cell, put the day of the week of your interest (e.g. 2019-01-03).
In the A3 cell, use this formula to calculate the difference in weeks (in case your week begins at Mondays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-2), B2, "d") / 7), 0) + 1
Or this one (in case your week begins at Sundays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-1), B2, "d") / 7), 0) + 1

Excel : Weeknumber within month with criteria

I'm trying to make a formule to calculate the weeknumber within a week but with certain criteria. The week always starts on a monday. But if the thursday of that week is in the next month, then that weeknumber is part of the next month.
[enter image description here][2]
Right now I have the following formula:
=INTEGER((6+DAY(A4+1-WEEKDAY(A4-1)))/7) where A4 is the date.
This already calculates the weeknumber within the month, but not with the criteria of thursday. An extra added criteria is that the weeknumber should start from 6am on monday instead of at midnight. But that I can solve with an extra column to check for that.
Thanks in advance!
Consider working out the week number from the previous week number:
If it is Monday then
If following Thursday goes into the next month, reset to 1
Else increase by 1
Else use same value
So starting with a 1 in E4
=IF(WEEKDAY(A5)=2,IF(MONTH(A5+3)>MONTH(A5-4),1,E4+1),E4)
entered in E5 and copied down.
EDIT
Above works for 2017 but would need slight change to work for 2018 and onwards because month decreases from 12 to 1 across year boundary:
=IF(WEEKDAY(A5)=2,IF(MONTH(A5+3)<>MONTH(A5-4),1,E4+1),E4)
I cant upload a workbook but here is a solution:
Row 2 is headers
Row 3 is empty
B4 going down is the date(01/01/2017 up to 31/12/2017)
C4 =WEEKDAY(B4,2)
D4 =VLOOKUP($C4,$L$3:$M$9,2,0)
E4 =MONTH(B4)
F4 to J4 are empty
F5 =IF(C5=1,F4+1,F4)
G5 =IF(C5=4,11,0)
H5 =IF(MAX(E5:E11)-MIN(E5:E11)<>0,22,0)
I5 =IF(AND(C5=4,SUM(G5:G11)+SUM(H5:H11)>22),I4+1,0)
J5 =IF(H6-H5<0,1,IF(H6=22,J5,IF(OR(C6=1,I6<>0),J5+1,J5)))
L3 to M9 are vlookups
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
7 Sunday
Does that work ok for you?
In my experience most of those week number questions can be answered with some variation of your original formula - in this case this version should cater for Monday week start with the Thursday determining the month
=INT((6+DAY(B4+4-WEEKDAY(B4-1)))/7)
That works for a date in A4 but assuming you have a date/time in A4 and the week doesn't start until 06:00 on Monday then you can tweak that as follows:
=INT((6+DAY(B4+3.75-WEEKDAY(B4-1.25)))/7)

Randomly generate 2 dates per week over 2 years

How do I write an excel formula, which randomly picks 2 dates in each week over a 2 year period, where:
The 2 dates per week are not the same as each other
So this should not happen:
05/02/2015
05/02/2015
The first date in any given week is always before the second date of that same week:
So this should not happen:
06/02/2015
05/02/2015
Where Sunday is the beginning of the week and Saturday is the end of the week:
Here is an example of what I am after:
week day date
1 1 01/01/2015
1 2 03/01/2015
2 1 05/01/2015
2 2 08/01/2015
And so on, all the way to the end of 2016.
This is what I have so far, but this only randomly gives me a day of a week, and doesn't fulfill any of the criteria I've described above:
=CHOOSE(WEEKDAY(ROUND((RAND()*(7-1)+1),0)),"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
There are 21 different combinations of 2 days in a week - to ensure an even distribution you can use a helper column, so assuming your weeks start at A2 and days at B2 (always showing 1 then 2 in days column for each week) then use this formula in D2
=IF(B2=1,RANDBETWEEN(1,21),"")
and this formula in C2
=IF(B2=1,E$1+MATCH(D2,{1,7,12,16,19,21})-8+A2*7,C1+D1-LOOKUP(D1,{1,7,12,16,19,21})+1)
where E1 contains the start date (a Sunday) of week 1
fill both formulas down the column
You can hide column D if required
See example here

Resources