Excel add hours to date excluding weekends and holidays - excel

I would like to add hours on a start date and skip weekends and holidays in an Excel file.
The hours would be 24, 36 and 48.
So if the start date and time are 4 Mar 2019, 13:42, the end date and time should be :
24 hours: 5 Mar 2019, 13:42
36 hours: 6 Mar 2019, 01:42
48 hours: 6 Mar, 2019, 13:42
I am now using this formula:
=WORKDAY(E2,G2/24,Holidays!$A$2:$A$18)+MOD(E2,1)
E2 is the start date and time in mm/dd/yy hh:mm format, G2 is the number of hours, Holidays!$A$2:$A$18 is the range of holiday.
This formula works totally fine for 24 hours and 48 hours, however, it is not working for 36 hours. It would be much appreciated if someone would help me to solve this problem.

Construct a simple date from addition and then convert it to the workday.
=WORKDAY(A2+B2/24-1, 1, Holidays!$A$2:$A$18)+MOD(A2+B2/24, 1)

Related

Excel: calculate which occurance of a weekday, within the month, from any given date e.g. fifth Friday

I am not very good at Excel. In the NHS (UK) we often schedule activity by looking at the columns on a calendar (e.g. All day theatre list Mondays week 1,3,5). This means on the first Monday, third Monday and if present fifth Monday. Using a printed calendar you can see the columns, for example Mondays in Jan 2023 where there are five.
When planning, it would be great to have a formula that would accept a date, and return the ordinal of the weekday for that month e.g.
Jan 02 2023 = 1
Jan 28 2023 = 4
Jan 29 2023 = 5
Jan 30 2023 = 5
I have searched and found the WEEKNUM function, but this counts rows on the calendar not giving the result I need.
Any help gratefully received
Kind Regards Gavin Holt
This should return those values:
=-INT(-(DAY(YourCellWithTheDate))/7)

Weeknum that doesn't start from 1st every year

How can i start weeknum from first week in 2018 and go on through 2019, 2020, 2021, 2022... without starting the count from 1 every year. Ex: if 2018 has 44 weeks i want the weeknum(1-1-2019) to return 45 not 1 and so on.
If you Week starts on Monday use:
=INT((A1-"1/1/2018")/7)+1
If your week starts on Sunday:
=INT((A1-"1/1/2018"+1)/7)+1

How to calculate no of days spent per month from the data in MS Excel?

I have a data which has a hotel check in date and check out date. I would be calculating the number of days spent at the hotel, I would simply subtract both of them and I have the days difference.
I now have to pick up the customers who stayed for more than 31 days and find out how many days they had spent per month. For example, some one checking in on 18th July 2015 and checked out on 18th September 2015, there should be multiple columns, corresponding to that cust which reads 13 31 18, for days spent per month. (July, Aug, Sept)
Example data and sample output :
Client Check In Check Out
Majestica Inn 22-May-15 22-Jun-15 31 9 22
Twin Tree 29-May-15 30-Jun-15 32 2 31
Connaught Mews 1-Jun-15 31-Jul-15 60 29 31
Majestica Inn 18-Jul-15 18-Sep-15 62 13 31 18
Majestica Inn 18-Jul-15 18-Sep-15 62 13 31 18
I am new to Excel, please help.
if you can be flexible about the number of columns then you can use the below formulas to get the desired output.
Formula To Get The Days:
Remark: paste this formula in cell e2 and then drag & copy.
=IFERROR(IF(AND(MONTH(E$2&"-"&YEAR($B3))>=MONTH($B3),MONTH(E$2&"-"&YEAR($C3))<=MONTH($C3)),IF(MONTH(E$2&"-"&YEAR($B3))=MONTH($B3),DATEDIF($B3,EOMONTH($B3,0),"D"),IF(MONTH(E$2&"-"&YEAR($B3))=MONTH($C3),DATEDIF(DATE(YEAR($C3),MONTH($C3),1),$C3,"D")+1,DATEDIF(DATE(YEAR($C3),MONTH(E$2&"-"&YEAR($B3)),1),EOMONTH(DATE(YEAR($C3),MONTH(E$2&"-"&YEAR($B3)),1),0),"D")+1)),""),"Err")
Formula For Concatenating:
=IFERROR(DATEDIF($B2,$C2,"D")&IF(E2<>"",",","")&CONCATENATE(E2,IF(F2<>"",",",""),F2,IF(G2<>"",",",""),G2,IF(H2<>"",",",""),H2,IF(I2<>"",",",""),I2,IF(J2<>"",",",""),J2,IF(K2<>"",",",""),K2,IF(L2<>"",",",""),L2,IF(M2<>"",",",""),M2,IF(N2<>"",",",""),N2,IF(O2<>"",",",""),O2,IF(P2<>"",",",""),P2),"")
And If You Don't Want To Add any Columns Then Try This One......
Paste in Cell D2......
=IFERROR(SUBSTITUTE(DATEDIF($B2,$C2,"D")&","&IFERROR(IF(AND(MONTH("Jan"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Jan"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Jan"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Jan"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Jan"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Jan"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Feb"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Feb"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Feb"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Feb"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Feb"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Feb"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Mar"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Mar"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Mar"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Mar"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Mar"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Mar"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Apr"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Apr"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Apr"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Apr"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Apr"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Apr"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("May"&"-"&YEAR($B2))>=MONTH($B2),MONTH("May"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("May"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("May"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("May"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("May"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Jun"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Jun"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Jun"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Jun"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Jun"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Jun"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Jul"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Jul"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Jul"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Jul"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Jul"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Jul"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Aug"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Aug"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Aug"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Aug"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Aug"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Aug"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Sep"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Sep"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Sep"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Sep"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Sep"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Sep"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Oct"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Oct"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Oct"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Oct"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Oct"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Oct"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Nov"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Nov"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Nov"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Nov"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Nov"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Nov"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Dec"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Dec"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Dec"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Dec"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Dec"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Dec"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&"0|",",0|",""),"")
Good Luck .............

Find the end-of-month date from any date entered in MS Excel

I need to take the date from one cell, find the end of the month that that date falls into, then add one calendar month.
Example:
Enter jan 13: jan 13 end of month is Jan 31, + 1 month is Feb 28 (or 9 on leap year).
Feb 19: = March 31
March 2 = 30 April
March 30 = 30 April
March 31 = 30 April
etc etc
Is there an excel formula that will do this? I don't want any macro/ VBA stuff.
If you have 2007 or later than:
=EOMONTH("3/30/2016",1)
Use the Date function, add one to the month and set the Day to zero. This gives the last day of the month. To get the last day of the next month add two to the month.
=DATE(YEAR(E3),MONTH(E3)+1,0)
=DATE(YEAR(E3),MONTH(E3)+2,0)

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)

Resources