YEAR() fitting to WEEKNUM(...,21) in Excel - 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

Related

excel if date falls on weekend default to previous friday

I have the following two functions in different columns and I need to apply a function to both :
=DATE(YEAR(E5);MONTH(E5);DAY(E5))
=TRUNC([#CAT]-TIME(10;0;0))
For both of them I need to default to a Friday if the date falls over the weekend. if date date is during the week it needs to keep the weekday date.
e.g: Sunday 2018/03/11 needs to be 2018/03/09
e.g: Monday 2018/03/5 needs to stay the same 2018/03/05
I have tried using an IF statement with a Weekday (1-7) but when its false it minus a day or two from the date (So on a Thursday it goes to Tuesday)
=WORKDAY(your_formula +1;-1)
will do what you want.
If your_formula resolves to a Sat or Sun, and we add one(1) day, then subtract one (1) workday, the preceding Fri will be the result, Since either Sun or Mon minus one workday --> Friday.
To literally get what you're after, I used this formula:
=IF(WEEKDAY(A2)=1,A2-2,IF(WEEKDAY(A2)=7,A2-1,A2))
On my machine Sunday is 1, and Saturday is 7.

Change Date Settings in Spotfire

The default Spotfire Work Week starts on Sunday and ends on Saturday.
I would like to adjust that default value so it starts on Monday and ends on Sunday. I would also like to adjust the work week value itself and my company's work week is one less than the default Spotfire value.
So if I'm looking at 2016, work week 1 starts Monday January 4th and ends Sunday January 10th.
Thanks!

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

Microsoft Excel - Date Sequence

I had a look for this question before I asked, but sorry if it's a repeat.
In a spreadsheet, I want to employ a date sequence.
eg. Stock Arrives - Friday 22nd February 2013
then, on the 22nd of Feb, that date CHANGES to the next 7 days.
eg. Stock Arrives - 1st March 2013
and then repeats this indefinitely.
Is there any way to do this?
If you want to always show the next Friday you can use this formula
=TODAY()+8-WEEKDAY(TODAY()+2)
That will show Friday 15th Feb 2013 right now.....but on 15th feb it will change to showing 22nd Feb
For other days just change the +2 at the end, e.g. +3 will give you next Thursday, +4 will give you next Wednesday, +5 will give you next Tuesday etc.
This is some way you could do this though I am not sure if this is what you want.
=B1+FLOOR((TODAY()-B1)/7,1)*7
Basically, have a cell hold the start date of the stock inventory (first date in the past where you received this stock). You need to have also the number of days between restocking (here I hardcoded 7). Then you can just use the floor of the difference between today and that date divised by the restocking time. This will give you a step-function-style behaviour.

Does Excel have a function to calculate Canadian federal holidays?

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)))

Resources