Find fourth Thursday each month and if NASDAQ closed that day, take next day - excel

I am working in Excel where I need to find the fourth Thursday in each month but if on that day NASDAQ is closed take the day after. I have this formula for each fourth Thursday:
=DATE(YEAR(A2),MONTH(A2),CHOOSE(WEEKDAY(DATE(YEAR(A2),MONTH(A2),1)),26,25,24,23,22,28,27))
but I am not be to get the next business day where the fourth Thursday is any one of:
01-Jan-14
20-Jan-14
17-Feb-14
18-Apr-14
26-May-14
03-Jul-14
04-Jul-14
01-Sep-14
27-Nov-14
28-Nov-14
24-Dec-14
25-Dec-14

Please try appending to your formula:
+IF(OR(A2=41823,A2=41970,A2=41998),1,0)

Related

how to calculate the date from the year, week-of-year and day-of-week in EXCEL?

I have the Year, Week-of-Year and Day-of-the-Week as follows:
Year = 2022 (A2) ; Week Year = 35 (B2); Week Day = 4 or Thursday (C2)
and I would like to estimate the Date as dd.mm.yyyy, which is highlighted in yellow as it shows in the EXCEL picture.
I tried many formulas, but I am sure there might be an easy one.
I think you are counting the weeks starting from zero because for 9/1/2022 (YYYY/MM/DD format) the corresponding week is 36 as per the result of function WEEKNUM(DATE(2022,9,1)). In order to use the logic to multiply the number of weeks by 7. You need to use as a reference the first day of the year, if it was a Sunday, if not then go back to the previous Sunday, so you can count the entire week. Bottom line use as a reference date, the Sunday of the first week of the year, not the first day of the year (YYYY/1/1)
Here is the approach we use in cell E2:
=LET(y, A2:A6, wk, B2:B6, wDay, C2:C6, fDay, DATE(y,1,1), seq, SEQUENCE(7),
fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2)) + 7*wk
+ XLOOKUP(wDay, TEXT(seq,"dddd"), seq-1))
We use the LET function to avoid repeating the same calculation. The following expression finds the previous Sunday if the first day of the year (fDay) was not a Sunday:
fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2))
The XLOOKUP function is used to get the numeric representation of the weekday and use the TEXT function to generate the weekdays in a long format. Since we count the entire week, if the weekday is a Sunday (column C in my screenshot), then we don't need to add any day to our reference date, that is why we use seq-1.
Here is the output for several sample data. Assuming the week count starts with zero, if not the formula needs to be adjusted as also the input data.
Notice that the year 2021 started on a Friday, so if we want to find a day for the first week (0) before Friday it will return a date from the previous year. Like in the case of Monday. If you want an error message instead, then the formula can be modified as follow:
=LET(y, A2:A6, wk, B2:B6, wDay, C2:C6, fDay, DATE(y,1,1), seq, SEQUENCE(7),
result, fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2)) + 7*wk
+ XLOOKUP(wDay, TEXT(seq,"dddd"), seq-1),
IF(YEAR(result) <> y, "ERROR: Date from previous year", result))
I found the solution:
Year = 2022 (A2) ; Week Year = 35 (B2); Week Day = 4 or Thursday (C2)
=DATE (A2,1,3)-WEEKDAY(DATE(A2,1,3)) + 7 * B2 + C2 - 6
I found this solution, but you need to do further testing if it really works.
I calculate month from week: =+MONTH(DATE(YEAR(A2);1;1)+B2*7-1)
I calculate week day number from week day name: =MATCH(D2;{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"};0)
And then make date using: =DATE(A2;C2;E2)

moment.js how to set startOf week to monday on current week?

I want to make the date of startOf("week") its start from Monday on current week
Is it possible for make this? My code:
moment().startOf("week").toDate();
This startOf start from saturday proof startOf start from saturday
Take a look at the First Day of Week and First Week of Year section
From the docs (emphasis is mine)
Locale#week.dow should be an integer representing the first day of the week, 0 is Sunday, 1 is Monday, ..., 6 is Saturday.
So just by running this code before doing any calls to moment
// From 2.12.0 onward
moment.updateLocale('en', {
week : {
dow : 1
}
});
It will set the first day of the week to Monday.
After that calling moment().startOf("week").toDate() will give you a Monday.

Get the first Friday of the Quarter of Today's Date

I was trying to get the first Friday of the quarter of today's date or any given date. Let's say the date is 12/06/2020, which falls to the 2nd quarter of the year. I should be able to get the first Friday of the 2nd Quarter and that should be April 3rd.
I was only been able to get the quarter of a given date, which you can see in the code below. Been stuck here for a while. Thanks in advance.
quarter = Int((Month(Now) + 2) / 3)
Here's a function that takes a date and returns the first Friday of the quarter:
Function FirstFridayOfTheQuarter(MyDate As Date) As Date
Dim FirstDayOfTheQuarter As Date
FirstDayOfTheQuarter = DateSerial(Year(MyDate), Int((Month(MyDate) - 1) / 3) * 3 + 1, 1)
FirstFridayOfTheQuarter = DateAdd("d", (13 - Weekday(FirstDayOfTheQuarter)) Mod 7, FirstDayOfTheQuarter)
End Function
This function is taking advantage of the Weekday function that returns:
1 for a Sunday
2 for a Monday
3 for a Tuesday
4 for a Wednesday
5 for a Thursday
6 for a Friday
7 for a Saturday
In case you want a non VBA solution:
My formula is:
=CEILING(EOMONTH(DATE(YEAR(A1);ROUNDUP(MONTH(A1)/3;0)+(ROUNDUP(MONTH(A1)/3;0)-1)*2;1);-1)-5;7)+6

Insert week column in Excel

I have a column in excel that has the day.
I want to add another column that will extract the week of that day (Mon-Sun) and display it as week ending on that Sunday's date.
Day
4/20/2019
4/21/2019
4/22/2019
4/23/2019
4/24/2019
4/25/2019
Expected Output
Day Week
4/20/2019 4/21/2019
4/21/2019 4/21/2019
4/22/2019 4/28/2019
4/23/2019 4/28/2019
4/24/2019 4/28/2019
4/25/2019 4/28/2019
Does anyone know how to add this column using excel functions?
WEEKDAY with the second parameter as 2 gives a number between 1 to 7 (7 being Sunday) for the day of the week. You can add to the date, the amount of days till that number becomes 7, in other words:
=A2+(7-WEEKDAY(A2,2))

How to get week start and week end in excel for given month only

As I was new to excel, I am working on a use case where I want to get week start and week end dates of a given month,
I am using following formulae which is giving me next month date followed by weekend.
=A7+(6-WEEKDAY(A7,2)+1)
Week Start Week End
7/1/18 7/1/18
7/2/18 7/8/18
7/9/18 7/15/18
7/16/18 7/22/18
7/23/18 7/29/18
7/30/18 8/5/18
How can I modify or have a new formulae which gives me month end date, if my weekend is on next month
Expected output should be
Week Start Week End
7/1/18 7/1/18
7/2/18 7/8/18
7/9/18 7/15/18
7/16/18 7/22/18
7/23/18 7/29/18
7/30/18 7/31/18
For month like Feb as it is unable to caluculate the formula it should return 0
Week Start Week End
2/1/18 2/4/18
2/5/18 2/11/18
2/12/18 2/18/18
2/19/18 2/25/18
2/26/18 2/28/18
1/0/00 1/1/00
You just need to wrap the result of your original formula in MIN and compare it to EOMONTH.
=MIN(A7+(6-WEEKDAY(A7,2)+1), EOMONTH(A7, 0))
As far as Feb goes, you need to compare te current value with the one either above or below to determine whether month(date)<>month(date+7) and you have not shown enough of how your data structure transcends months to do that.

Resources