Does Excel have a function to calculate Canadian federal holidays? - excel

I'm trying to figure out how to calculate the past/future Canadian federal holiday dates to use the NETWORKDAYS function in the cell. Because the dates of the holidays change every year, is there a function or VBA code that I can use to calculate this?
For example, I have a 10 year project and I want to calculate the variance between the beginning date and the end date, excluding the weekends and holidays.
Like, Civic holiday is on the 1st Monday of August. It was on the 1st in 2011, but in 2012 it was on the 6th.
Easter Monday was on the 25th in 2011, but on the 9th in 2012.
Becuase NETWORKDAYS need exact date of the holidays in order to work, I need to calculate the future holiday dates (10-15years into the future)
I hope this makes sense...

You can make a list quite easily with a formula approach e.g.for Labour Day list years only in A2 down and in another column in row 2 use this formula
=DATE(A2,9,8)-WEEKDAY(DATE(A2,9,6))
that will give the date of First Monday in September for the relevant year - copy formula down column
Edit: Here's a workbook with all holidays calculated from 2000 to 2099 as per your rules, I think. If you want dates before 2000 then just change the years in column A and the dates will change automatically
I would add a couple of blank columns to the range, e.g. make C2:M101 = holidays, then you can use that named range in any NETWORKDAYS/WORKDAY function - the extra columns would allow you to enter any "ad hoc" holidays

I know I'm a little late to the thread but for some reason the link to your file doesn't open. I would love to see how you calculate the Canadian holidays. I have found solutions for: Labour Day, Easter, Good Friday and Victoria Day but still looking for the rest.
Labour Day
=DATE(A2,9,8)-WEEKDAY(DATE(A2,9,6))
Easter
=FLOOR("5/"&DAY(MINUTE(A2/38)/2+56)&"/"&A2,7)-34
Good Friday
=FLOOR(DATE(A2,5,DAY(MINUTE(A2/38)/2+56)),7)-36
Victoria Day
=DATE(A2,5,25)-WEEKDAY(DATE(A2,5,25),3)-(7*(WEEKDAY(DATE(A2,5,25),3)=0))
* 4 digit year must be in A2 *

The working days are from Monday to Friday, excluding the holidays.
Some holidays taking place during weekend should be moved to next Monday (e.g. Canada Day, Boxing Day, New Year), or previous Friday (e.g. Christmas)
The following are the formulas for the holidays in the province of Ontario, Canada, if the fiscal year is in FYear
Holyday Formula
New Year =WORKDAY(DATE(FYear,1,0),1)
Family Day =DATE(FYear,2,22)-WEEKDAY(DATE(FYear,2,6))
Good Friday =FLOOR(DATE(FYear,5,DAY(MINUTE(FYear/38)/2+56)),7)-36
Victoria Day =DATE(FYear,5,25)-WEEKDAY(DATE(FYear,5,23))
Canada Day =DATE(FYear,7,1)+(WEEKDAY(DATE(FYear,7,2))<3)*(3-WEEKDAY(DATE(FYear,7,2)))
CivicDay =DATE(FYear,8,8)-WEEKDAY(DATE(FYear,8,6))
LaborDay =DATE(FYear,9,8)-WEEKDAY(DATE(FYear,9,6))
Thanksgiving =DATE(FYear,10,15)-WEEKDAY(DATE(FYear,10,6))
Christmas =DATE(FYear,12,25)-(WEEKDAY(DATE(FYear,12,26))<3)*WEEKDAY(DATE(FYear,12,26))
Boxing Day =DATE(FYear,12,26)+(WEEKDAY(DATE(FYear,12,27))<3)*(3-WEEKDAY(DATE(FYear,12,27)))
Next New Year =WORKDAY(DATE(FYear+1,1,0),1)

I found this page very useful, but I have a couple of additions. My use case is that I want to know when a stat holiday occurs even when it moves to a different day like Friday or Monday. These formulas apply to a table where #Year contains the year as a simple number.
U.S. Independence day behaves differently. If July 4 is a Saturday then the holiday is on 3 July. If July 4 is a Sunday then the holiday is 5 July. I found writing these as nested IF statements more straightforward:
=IF(WEEKDAY(DATE([#Year],7,4))=7, DATE([#Year],7,3), IF(WEEKDAY(DATE([#Year],7,4))=1,DATE([#Year],7,5),DATE([#Year],7,4)))
Next, the formulas above don't work for years like 2021 where Christmas and Boxing Day were a Saturday and Sunday. Again I think nested IFs work better.
We know that if Christmas Day (Dec 25) is on a Saturday, then the stat holiday is on Dec 27, and if it is on a Sunday then the stat holiday is Dec 26. =IF(WEEKDAY(DATE([#Year],12,25))=7,DATE([#Year],12,27),IF(WEEKDAY(DATE([#Year],12,25))=1,DATE([#Year],12,26),DATE([#Year],12,25)))
Similarly, we know that if Boxing Day is on either a Saturday or a Sunday (meaning Christmas was Saturday), then the stat is on Dec 28. And if it falls on a Monday (meaning Christmas was Sunday), then it moves to Dec 27.
=IF(OR(WEEKDAY(DATE([#Year],12,26))=7,WEEKDAY(DATE([#Year],12,26))=1),DATE([#Year],12,28), IF(WEEKDAY(DATE([#Year],12,26))=2, DATE([#Year],12,27), DATE([#Year],12,26)))

Related

Calculate Week of The Month with Straddling Weeks - Excel

I am trying to calculate the weeks of the month, 1-4 or 1-5, where the calendar week that contains the first calendar day of the month is always week 1. So for example, February 1, 2018 falls on a Thursday so the dates Monday January 29 - Sunday February 4 would be week one of February.
I was using the formula =INT((DAY(D2)+6)/7) - which seemed to work until the week splits and crosses the calendar month. It counted the days the cross over from January as week 5 rather than week 1 of the next month.
Try this and see if it works:
=IF(MONTH(A2)=MONTH(A2+7-WEEKDAY(A2,2)),CEILING(((DAY(A2)+WEEKDAY(A2-DAY(A2)-1)))/7,1),1)-AND((WEEKDAY(A2-DAY(A2))=1),MONTH(A2)=MONTH(A2+7-WEEKDAY(A2,2)))
Is the following Sunday in the same month as the Date (in A2)
If False, Week = 1
If True
use last Sunday of preceding month as base for week count.
Adjust if month starts on a Monday and we are in the first week (there's possibly a better way to do this adjustment)

Excel weeknum function returns wrong week

Question is as in title.
I have a cell, "D4", with the date "09/07/2016" in it. Adjacent cell has formula "=weeknum(D4,1)". The output of this function is "28". But on a Sunday-Saturday basis, Saturday the 9th of July wasn't in week 28 - it was in week 27.
I thought this might be something to do with Saturday/Sunday and when the week starts and finishes, etc, so I tried multiple different dates from last week - Monday the 4th, Tuesday the 5th, Wednesday the 6th, etc. In each case, "weeknum" returns a value of "28".
I only noticed the problem because I have a macro which uses the value of the cell with the week number to look for a spreadsheet saved by our accounts team on a weekly basis. As they have - correctly - saved the spreadsheet as "week 27", it didn't work. I initially assumed that the accounts team were wrong, but I checked online and they are correct.
How could this happen? Surely Excel can't be wrong and I must have made a mistake of some sort?
I know that there is an issue with Excel not following ISO standards for when weeks 53 and 1 begin and end, but I don't see how that could affect a mid-year week.
It did occur to me that the issue might be to do with UK versus US date formatting. But, of course, the 7th of June wasn't in week 28 either.
That all is documented in WEEKNUM.
There are two systems used for this function:
System 1 The week containing January 1 is the first week of the
year, and is numbered week 1.
System 2 The week containing the first Thursday of the year is the
first week of the year, and is numbered as week 1. This system is the
methodology specified in ISO 8601, which is commonly known as the
European week numbering system.
Syntax
WEEKNUM(serial_number,[return_type])
Return_type Week begins on System
...
21 Monday 2
So =WEEKNUM("09/07/2016",21) will calculate as defined in ISO 8601 since Return_type 21 is the only one with System 2.
ISOWEEKNUM
=ISOWEEKNUM("09/07/2016")
will also do it.
=ISOWEEKNUM(a2)-1 returns the correct week for me, the same as =WEEKNUM(a2,21)-1

How do I calculate a date by adding 30 calendar days, where end date must be business day?

I'm wondering if this is possible. I am creating a spreadsheet to track project due dates. Each project must be completed by the 30th calendar day, but must be turned in on a business day.
Currently, I am just adding 30 days to the start date but this means some due dates aren't always accurate. For example, if the 30th day is Saturday, April 2nd, then the real due date would be Friday April 1st.
Is there a way to construct a conditional such that the due date equals the 30th calendar day, unless that falls on a weekend / holiday, where it then falls on the next earliest business day?
I've been struggling to figure out a way to do this.
For English settings in Excel, with a date in A1, in B1 enter:
=IF(TEXT(A1+30,"DDDD")="Sunday",A1+28,IF(TEXT(A1+30,"DDDD")="Saturday",A1+29,A1+30))
This simple-minded approach only handles Saturdays and Sundays, not arbitrary holidays.
I would prefer more elegant way like using WORKDAY.INTL
=WORKDAY.INTL(A2+31,-1,1,E2:E)
Explanation: start date + 31 days (1 day more than maximum calendar days)
then subtract 1 working day - going to last previous working day
Reason: because this formula does know when are weekends (by using variables) and also knows to skip hollydays by a custom list.
here is an example sheet you can use
Revised after comment:
Try this:
=(A4+30)+CHOOSE(WEEKDAY(A4+30),1,0,0,0,0,0,-1)
Your date, in A4, + 30 days, then add an amount of days until the next workday. If A4 + 30 is a Saturday it will subtract 1 day, a Sunday will add 1.

YEAR() fitting to WEEKNUM(...,21) in Excel

I'm looking for a way to specify return 2015 for a date within this week, but in Calendar Year 2014.
This current week according to the Thursday system is Week 01/2015. But the Year function will still return 2014.
Something like:
IF(AND(WEEKNUM(TODAY(),21)=52,WEEKNUM(TODAY()+7,21)<>53),YEAR(TODAY())+1,YEAR(TODAY())
but a little bit more reliable and elegant.
Anybody got something?
Happy Happy
Ben-san
The "Year" of the week is determined by the year of the Thursday of that week (assuming ISO week numbers) so you can just find the Thursday and then get the year of that date, i.e. for any date in A1
=YEAR(A1-WEEKDAY(A1,3)+3)
or, similarly, for today's date
=YEAR(TODAY()-WEEKDAY(TODAY(),3)+3)
This works for any date in any year.......and might put days in Jan in the previous year also, e.g. 3rd Jan 2016 is in the last week of 2015

Excel - Times a month and day occur between 2 dates

I have an Excel sheet where someone types in the date for a yearly bill. I need to know how many times we need to pay that bill between 2 dates.
For example if a bill is due every year on May 31st, the user will type in 5/31/2014. I need to know how many time we will pay that bill between 5/15/2014 and 5/15/2018. (The between dates will change). I can't just take the number of years between the start and end dates because in the example above the start and end dates could be 6/1/2014 and 5/30/2018, in which case I only have to pay the bill in 2015, 2016, and 2017, which makes 3 times.
I have this formula which calculates the number of times a certain day occurs between 2 dates: SUMPRODUCT(--(DAY(ROW(INDIRECT($Q$2&":"&$R$2)))=F4))(Q2 is the begin date, R2 is the end date, and F4 has the day of the month) But I can't figure out how to get this to work for a month and day.
Assuming the specific date in G4 you can use this version
=SUMPRODUCT(--(TEXT(ROW(INDIRECT($Q$2&":"&$R$2)),"ddmmm")=TEXT(G4,"ddmmm")))

Resources