Time and date calculations

phillipcook

Board Regular
Joined
Jun 25, 2015
Messages
87
hi all.

I am having a little trouble working out a couple of formulas. What I have is the following:

column A: DATE
column B: START TIME
column C: FINISH TIME
column D: PUBLIC HOLIDAY DATES

what I need to calculate is the following 5 different formulas:
1 formula
If the date is between Monday to Friday and is not a public holiday, the amount of hours and minutes worked outside of 6am to 6pm.

2 formula
If the date is between Monday to Friday and is not a public holiday, the amount of hours and minutes worked between 6am and 6pm.

3 formula
if the date is a Saturday

4 formula
if the date is a Sunday

5 formula
if the date is a public holiday (public holiday dates are listed in a column D for the year.

Thanks heaps in advance guys
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I am pretty sure there are other/better ways of calculating these, but here is my effort:

Code:
1 -  =IF(NETWORKDAYS(A2,A2,D2:D15)>0,(C2-B2)-(MIN(18/24,C2)-MAX(6/24,B2)),0)
2 -  =IF(NETWORKDAYS(A2,A2,D2:D15)>0,MIN(18/24,C2)-MAX(6/24,B2),0)
3 -  =WEEKDAY(A2,16)=1
4 -  =WEEKDAY(A2,16)=2
5 -  =ISNUMBER(MATCH(A2,D2:D15))

This assumes that the actual dates(i.e.not the header) for public holidays starts in D2 and goes to D15 - - if there are more public holidays than that then you would need to amend.
 
Upvote 0
5 should be -
Code:
=ISNUMBER(MATCH(A2,D2:D15[COLOR=#ff0000],0[/COLOR]))

Also for 1 & 2 I would format the cells using the custom format [HH]:mm
 
Last edited:
Upvote 0
Awesome mate!!!

I have done them and they seem to work brilliantly, however I made one mistake. With formula 3, I need it to also exclude public holidays. Not sure how to do this.

With the last 3 formulas I have managed to make them show a blank if there is no start date, but I can’t seem to figure out how to make the first two display blanks if their is no start date. Could you please help me out with this one?

thank you for all the help!!!
 
Upvote 0
Sorry I made a mistake. Only formula 5 I can make it show up as a blank if the start time is missing. Would you please help me make the other 4 formulas show a blank result if the start time is missing?
Thanks heaps!!
 
Upvote 0
I you still want one and two to show a zero if the start date isnt blank but the number of hours is zero then:

Code:
1  -   =IF(A2="","",IF(NETWORKDAYS(A2,A2,D2:D15)>0,(C2-B2)-(MIN(18/24,C2)-MAX(6/24,B2)),0))
2  -   =IF(A2="","",IF(NETWORKDAYS(A2,A2,D2:D15)>0,MIN(18/24,C2)-MAX(6/24,B2),0))

And for three - is it likely a public holiday is on a Saturday?

You can check that the date doesn't appear on the list of public holidays:

Code:
=AND(WEEKDAY(A2,16)=1,ISERROR(MATCH(A2,D2:D15,0)))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top