Excel exclude date range work hour calculation for non workdays - excel

How to exclude this calculation for Saturdays and Sundays or have 0 returned for week-ends?
=IF(AND(DATE($L$1,10,1)>=A9,DATE($L$1,6,17)<=A9),6,8.75)
This formula calculates the hours to be worked against a date range being 6 hours for summer schedule (from 16 June to 30 September) and the remaining days returns a value of 8.75 hours. $L$1 returns the year (value of cell L1 e.g. 2016).
I am aware of the WORKDAY function, but I cannot get the formula to work.
What I am after is to have a 0 returned for any given Saturday or Sunday.

No need for WORKDAY function. Simply check if WEEKDAY of the date is not Saturday or Sunday.
=IF(WEEKDAY(A9,2)>5,0,IF(AND(DATE($L$1,10,1)>=A9,DATE($L$1,6,17)<=A9),6,8.75))
To check if the date in A9 is or is not a holiday, WORKDAY is the wrong approach since WORKDAY is thought to calculate the date of the workday not to check if a given date is a workday.
We can use COUNTIF to check if the date in A9 is in a range with holidays.
Example: holidays dates are in $F$2:$F$4
=IF(OR(WEEKDAY(A9,2)>5,COUNTIF($F$2:$F$4,A9)>0),0,IF(AND(DATE($L$1,10,1)>=A9,DATE($L$1,6,17)<=A9),6,8.75))

Related

Excel how to convert weeknum to date when crossing the year

I have a table with Date column and weeknum column.
The weeknum column has below formula to create a srting: 2022/10.
=YEAR([#[Date]})&"/"&WEEKNUM([#[Date]],2)
I would like to get the start day and end day of the week converting from the string "2022/10".
I tried =DATE($M$1,1,-2)-(WEEKDAY(DATE($M$1,1,3))+(MID(M4,6,2)*7)) where $M$1 references current year and M4 references Year/ weeknum but it returns 10/17/2021. It should return 2/28/2022, and as the weeknumber increases. the returned dates decrease.
The dates of 2021/53 are correct, but the others got wrong.
How do I get fixed the dates?
You can do this by taking the weekday number of the date away from itself and adding 7-weekday to itself.
i.e.
If we use the first date on your list and we say weeks start on Monday:
The first day of the week (Monday) = E2-WEEKDAY(E2,2)+1 = 12/27/21
The last day of the week (Sunday) = E2+(7-WEEKDAY(E2,2)) = 01/02/22
Note: I have assumed your first date (12/27/2021) is in Cell E2
If you want Sunday to be the first day of the week, simply add a 1 instead of a 2 into the WEEKDAY part of the formula.

Find first date after today that matches a day-number and weekday

Given any date, how do I find the first month and year in the future where the 31st of that month falls on a Wednesday, in other words, for today, 11 November 2020, I would like to see (31) March 2021. [Updated: Returned month should be March 2021]
#prino,
You could make use of Excel's Iterative Calculation, setting Maximum Iterations to 1000.
In the example below, A1 is the given date and B1 receives the result (put the formula in B1):
=IF(B1=0,A1)+B1+IF(AND(WEEKDAY(B1,1)=4,DAY(B1)=31),0,1)
If you have Excel 365 then
=LET(DayInMonth, DATE(YEAR($A$2),MONTH($A$2)+SEQUENCE(336,,0,1),$B$2),
DOW, WEEKDAY(DayInMonth),
IsMatch, (DAY(DayInMonth)=$B$2)*(DOW=$C$2)*(DayInMonth>=$A$2),
XLOOKUP(1,IsMatch,DayInMonth,,0,1))
How it works:
Parameters are on the sheet (you could hard code these into the formula if you wish)
A2 is the start date (could be formula =TODAY())
B2 is the day number in the month
C2 is the day of week code (1..7 = Sunday..Saturday)
The calander repeats every 28 years. So only need to consider 12*28 = 336 months
DayInMonth is the specified date in each of the next 336 months, including this month. Note: if a month does not have the specified day (eg 31 September does'nt exist)
DOW is the day of Week code for those dates
IsMatch is 1 if calculated DayInMonth matches specified DayInMonth (this excluded non-existant dates) AND Calculated DOW matches specified DOW AND calculated date is on or after start date
XLOOKUP returns the date of the first 1 in the IsMatch array

how can i exclude FRI and SAT days from the calculation of days passed

I need to exclude FRI and SAT days from the formula which counts the days from date in cell A1 until the date of Today(), and subtracts A1 from Today()
i have already the formula which checks first if A1 has a value, if yes subtracts the value from Today(), if not it will say "NO VALUE"
i also know there is code to exclude FRI and SAT but i'm having a hard time incorporating it into my formula:
This will count 8 days from Start_Date in A1, and excludes FRI and SAT:
=WORKDAY.INTL(A1,8,7)
This is my current formula which shows the number of days, but i want it to skip FRI and SAT:
=IF((A1<>""),((TODAY()-A1)),"NO VALUE")
You can use NETWORKDAYS rather than WORKDAY:
=IF(A1<>"",NETWORKDAYS.INTL(A1,TODAY(),7),"NO VALUE")
It might not be the best way to do it but I found a work around.
You can calculate the total number of day and remove the number of Friday and remove the number of Saturday.
I found this that count how many Friday in a specific date range.
For example:
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(Date1&":"&Date2)))=5))
It basically retrieve all the date in the range in their numerical value and test if if it is a Saturday and give you the amount of Saturday between 2 dates.
In your case you could use it to remove the Friday and Saturday like below:
=IF((A1<>""),((TODAY()-A1-SUMPRODUCT(-(WEEKDAY(ROW(INDIRECT(A1&":"&B1)))=5)) -SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(A1&":"&B1)))=6)))),"NO VALUE")
Where B1 is today's date.
And example:
example using the formula
Hope this helps.

In Excel, how to calculate # of days between a date range, counting only specific days of week

I'm trying to get # days between 2 dates, but had to count only days of the week specified per pair of dates in questions.
For example:
Date of operation = 9/1/2013 and 5/16/2014
Days of the Week in operation = Monday, Wednesday, Friday
I want to calculate total number of days in actual operation, given the days in operation per week.
If you have Excel 2010 or later you can use NETWORKDAYS.INTL function which allows you to customise which days are counted, e.g. the following formula will count Mondays, Wednesdays and Fridays between a start date in A2 and an end date in B2 (inclusive) while excluding holiday dates listed in H2:H10
=NETWORKDAYS.INTL(A2,B2,"0101011",H$2:H$10)
The string "0101011" defines the days to include - 0 is included, 1 is excluded - it starts with Monday
In earlier excel versions you can use this formula for the same result
=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A2&":"&B2)))={2,4,6})*(COUNTIF(H$2:H$10,ROW(INDIRECT(A2&":"&B2)))=0))
where {2,4,6} defines the weekdays to include (1=Sun through to 7=Sat)
The number of days between to dates is just date1 - date2.
One method is to divide the number of days in operation by the number of days in the week. In this case that would be 3/7. In this example, the number of days in operation would be 110.14 days. Below is your example. cell B4 has 1-sep-13, b6 has 16-may-14, both formatted as dates.
B
4 41518
6 41775
8 =B6-B4 Days
9 =B8/7 Weeks
10 =B8*3/7
01-Sep-13
16-May-14
257 Days
36.71 Weeks
110.14
To get more accurate, you would need to know which day of the week, weekday(), the first day in your range was and which day of the week your last day was.

Calculate the number of days of a date range occur between two dates

I have a datasheet that contains a list of start and end dates for a task. I need to calculate how many days between the start date and end date are part of our Christmas break (11th December to 7th January)
So for example,when start date is 10/12/2012 and end date is 12/01/2013, 28 of the days are between those dates. when the start date is 15/12/2012 and the end date is 12/03/2013, then 22 days of days are between those dates. If the start date is 10/12/2012 and the end date is 12/01/2014, 56 of the days are between those dates (because there's two years of the range).
I need to do this with a formula because of the requirements that I've been set.
Initially I decided to use the number of times Christmas Day (25th December) occurs and just calculate 4 weeks per occurrence.
The formula I used was
=FLOOR((E12-A25)/365,1)+IF(OR(MONTH(E12)=12,
MONTH(A25)=12),
IF(AND(DAY(A25)<=25,DAY(E12)>=25),1,0),
IF(OR(MONTH(A25)>=12,
IF(MONTH(E12)<MONTH(A25),
MONTH(E12)+12,
MONTH(E12))>=12),1,0))*28
But obviously this doesn't help if the range start and end date falls between those two dates.
Any suggestions? I'm at a dead end
Your date math on the second example is wrong -- there are 24 days in that range, not 22.
I can get you there for one holiday period:
LET:
A1 contain the holiday start (11-Dec-2012)
A2 contain the holiday end (7-Jan-2013)
B1 contain the start date
B2 contain the end date
FORMULA:
=MAX(MIN(A2+1,B2+1),A1) - MIN(MAX(A1,B1),A2+1)
The formula basically finds the overlapping date range, if there is one, and subtracts to get the number of whole days. The "+1" is because your "end dates" are actually inclusive, so for date math you need to have the holiday ending on 8 Jan, not 7 Jan, to capture that last day.
But this only works for a single year's holiday. You could store holiday ranges in other cells and use the same formula and add them all up, but you'll be limited to however many years you set up.
This formula will count dates between 11th December and 7th January inclusive within any date range, even across multiple years
=SUMPRODUCT((TEXT(ROW(INDIRECT(B1&":"&B2)),"mmdd")+0>=1211)+(TEXT(ROW(INDIRECT(B1&":"&B2)),"mmdd")+0<=107))
where your start date is in B1 and end date in B2
This converts every date in the range to a number , e.g. 1st Dec becomes 1201, 4th March becomes 304, then it counts those dates that are either greater or equal to 1207 (7th December) or smaller than or equal to 107 (7th January), so that will give 56 for your last example
You can shorten the formula if you subtract 7 from every date (based on 7th January as the end date) then you only need to check that resultant numbers are >= 1204, i.e.
=SUMPRODUCT((TEXT(ROW(INDIRECT(B1-7&":"&B2-7)),"mmdd")+0>=1204)+0)
.....and a third option which should also give the same result, closer to richardtallent's approach - gets the number of years and multiplies by 28 and then adjusts the figures based on the start/end date
=(YEAR(B1-7)-YEAR(B2-7)+1)*28-MAX(0,B2-DATE(YEAR(B2-7),12,11))-MIN(28,DATE(YEAR(B1-7)+1,1,7)-B1)

Resources