How to count days excluding weekends and holidays but start day/end day can be weekends /holidays? - excel

How to count days excluding weekends and holidays in excel. However, start day and end day can be weekends or holidays.
I have tried Networkdays function in excel using MAC. I also tried workdays function. And, i am new to this forum. Let me know if you are not able to understand anything.
Start Date(E) End Date (F)
2019-07-20 - 2019-08-01
2019-08-04 - 2019-08-06
2019-08-05 - 2019-08-07
2019-08-02 - 2019-08-07
2019-08-14 - 2019-08-20
Holiday list
Date(K) Description Day
8/12/19 - Eid - Monday
8/15/19 - Independence Day - Thursday
Excel formula:
= NETWORKDAYS(E2,F2,$K$7:$K$27)
Start date: Column E, End date: Column F, Holiday list: Column H
output expected output
9 8
2 1
3 1
4 2
4 2

Try using NETWORKDAYS.INTL to make sure that your weekend days are set to fall on Saturdays and Sundays.
For example:
=NETWORKDAYS.INTL(E2+1,F2-1,1,$H$2:$H$3)
Result:

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)

Google Sheets or Excel Function to return date based on value

I have this table in Google Sheets (or excel). The year is the two last digit of my code.
Code Duration Months
1 AC-26482-17 60
2 AC-26482-18 30
3
I would like to return the date in this format (If no data, just leave blanks).
Code Duration Months Start Expiration
1 AC-26482-17 60 01/01/2017 01/01/2022
2 AC-26482-18 30 01/01/2018 01/07/2020
3
Is there a way to achieve this?
You mean you want to add the duration in months to the start date? If so, your sample has the wrong expiration date. 30 months added to 1/1/2018 is not June 1st, but July 1st.
The formula in Excel is
=EDATE(C2,B2)
If you also want to calculate the start date from the last two characters of the code, given all dates are in this millennium, then you can use this for the start date:
=DATE(RIGHT(A2,2)+2000,1,1)
edit: To handle blank cells, you can check with IsBlank()
=if(isblank(a2),"",DATE(RIGHT(A2,2)+2000,1,1))
use:
=ARRAYFORMULA(IF(A2:A="",,DATE(IF(RIGHT(A2:A, 2)*1>=40,,20)&RIGHT(A2:A, 2), 1, 1)))
=ARRAYFORMULA(IF(A2:A="",,DATE(YEAR(C2:C), MONTH(C2:C)+B2:B, 1)))

Retutn only Buisness days in custom date function in excel

I have a date which I will need to increment the date by a day, month or year from the actual date. This is based of a list of fields below and is different per the input. Also each resultant date has to be a business day i.e not a weekend day or a bank holiday. Also if the resultant date is either Dec 25 or Jan 1st the day needs to move forward to the next business day (not a weekend day).
I have created this in Excel using a couple of formulas though it is a bit clunky.
Below is my data set
Business Date 15/05/2018
Tenor Settlement Value Settlement Period
ON 1 Day
TN 2 Day
SP 2 Day
SN 3 Day
1W 7 Day
2W 14 Day
3W 21 Day
1M 1 Month
2M 2 Month
3M 3 Month
In column E - I am using formula
=IF(D4="Day",$B$1+C4,IF(D4="Month",EDATE($B$1,C4),(TEXT($B$1,"dd/mm/")&(YEAR($B$1)+C4))+0))
In column F - I am using formula
=E4+LOOKUP(WEEKDAY(E4),{1,2,3,4,5,6,7},{1,0,0,0,0,0,2})
In column G - I am using formula
=F4+IF(AND(OR(TEXT(F4,"ddmm")="2512",TEXT(F4,"ddmm")="0101"),WEEKDAY(F4)>=2,WEEKDAY(F4)<=6),LOOKUP(WEEKDAY(F4),{1,2,3,4,5,6,7},{0,1,1,1,1,3,0}),LOOKUP(WEEKDAY(F4),{1,2,3,4,5,6,7},{1,0,0,0,0,0,2}))
In H I format the date in mm/dd/yyyy and I have my desired result.
storax has kindly created a function for me which replicates my excel formula in column E - on this thread Increment a date by a number of days, months or years
Function IncDate(ByVal dt As Date, ByVal add As Long, ByVal dmy As String) As Date
Select Case UCase(dmy)
Case "DAY"
IncDate = DateAdd("d", add, dt)
Case "MONTH"
IncDate = DateAdd("m", add, dt)
Case "YEAR"
IncDate = DateAdd("yyyy", add, dt)
Case Else
IncDate = dt
End Select
Could use some advise on how I could incorporate my formulas in columns F & G to make the process less clunky.
Manipulating the DATE function (DateSerial in vba) with the WORKDAY.INTL function seems to produce the correct business dates.
Put this in E4 and fill down.
=WORKDAY.INTL(DATE(YEAR(B$1)+(D4="year")*C4, MONTH(B$1)+(D4="month")*C4, DAY(B$1)+(D4="day")*C4)-1, 1, 1, holidays)
[holidays] is a named range (Formulas, Defined Names, Defined Name) with a Refers To: of,
=Sheet10!$Z$2:INDEX(Sheet10!$Z:$Z, MATCH(1E+99, Sheet10!$Z:$Z))

Difference between two dates in excel 2013

I want to calculate the time difference between two dates with the following criteria:
1) excluding sundays and public holidays
2) TIMING: Mon to Fri = 7 AM to 7 PM &
Sat = 7 AM to 3 PM
I tried a many formulas and nothing works for me.
please any ideas??
Eg: Start Time: 3/6/2015 10:00 AM
End Time: 4/6/2015 12:00 PM
Then I should get the difference as 13 hrs (excluding time out of business hours)
If start and end "timestamps" will always be within working hours then you can use a formula like this:
=(SUM(NETWORKDAYS.INTL(A2,B2,{1,"1111101"},H$2:H$10)*{12,8})-IF(WEEKDAY(B2)=7,8,12))/24+MOD(B2,1)-MOD(A2,1)
Assuming start date/time in A2, end date/time in B2 and holiday list in H2:H10
Format result cell as [h]:mm and if start time is today (Monday) at 14:00 and end time is exactly a week later you will get the result 68:00 (5*12 hour days and 1*8 hour Saturday)

Excel find date difference between minimum and maximum date in month

I'm trying to fix up a formula I have that's having some issues. It's supposed to track # days invoiced in a month, so the high-level idea is to take the maximum date in a month and subtract the minimum date in the month, and on error subtract the 1st day of the month. My current formula has issues adjust for invoices that may cross months, an example being 1/25 - 2/3 where if this were the only invoice, January should show 7 days invoiced and February would show 3. If there were another invoice from 2/15 - 2/28, I would want Feb to show the maxed invoice days, 14 in this example.
For reference here's what a table could look like:
A B C D E F
start month end month invoice begin invoice end Month Max Days invoiced
jan 1 feb 1 1/25/14 2/3/14 1/1 7
feb 1 feb 1 2/15/14 2/28/14 2/1 14
3/1
etc.........
I tried the formula below but it was erroring out, plus I don't think it will account for gaps in invoices like in my example.:
=IF(B2:B100=X1,MAX(D2:D100),) - IF(A2:A100=X2,MIN(C2:C100),A2)
'where column X is a list of months, X1 = 1/1, X2 = 2/1, etc.
No luck with this formula either, keeps erroring out and giving 0 values:
{=DATEDIF(IF(A2:A100=E2,MIN(C2:C100),),IF(B2:B100=E2,MAX(D2:D100),),"d")}
I appreciate your help!
Not sure exactly what you are looking for but you could probably make use of the EOMONTH() function. Here's an example of it:
=EOMONTH(A2,0)-A2+1
by the way - here is how you would get the start of the month:
=EOMONTH(TODAY(),-1)+1
Try the following per your comment below:
"I think this could be useful but I'm not sure it would work if the invoice end was, say, 2/21 or anytime before the EOM"
=IF(B3>=EOMONTH(A3,0),EOMONTH(A3,0)-A3+1,B3-A3+1)

Resources