Forum

Notifications
Clear all

Work Time Calculation

12 Posts
2 Users
0 Reactions
106 Views
(@shep)
Posts: 7
Active Member
Topic starter
 

Work time is Monday to Friday 9am to 5pm

In column A I have a list of dates/times to which i need to add 6 hours. If adding 6 hours takes me beyond 5 pm then the additional hours should be added to the next day starting at 9am

Example

Column A             Column B
20/01/2021 13:45 20/01/2021 19:45

Adding 6 hours takes me beyond 5pm so I need a formula that would return 21/01/2021 11:45

In addition if the example was on a Friday it should add the additional hours on from Monday as in the example below

Column A             Column B
22/01/2021 13:45 25/01/2021 11:45

 

Thanks for any help

 

Paul

 
Posted : 21/01/2021 6:46 am
(@questvba)
Posts: 125
Estimable Member
 

Hi Paul,

Here is a solution with a formula. 

BR,

Lionel

 
Posted : 22/01/2021 1:47 am
(@shep)
Posts: 7
Active Member
Topic starter
 

Hi Lionel

That is great thank you

Is it possible to adapt that formula so that if the start time is out of work hours (between 17:01 & 08:59) the 6 hours is added on from 09:00, so always giving the answer 15:00

Thanks in advance for any help

Paul 

 
Posted : 22/01/2021 10:03 am
(@questvba)
Posts: 125
Estimable Member
 

Paul,

A new version.

BR,

Lionel

 
Posted : 22/01/2021 12:53 pm
(@shep)
Posts: 7
Active Member
Topic starter
 

Hi Lionel

Thank you that is perfect

I struggle with time calculations in excel, so have been looking at your formula and whilst I could not have found that solution, I have looked at it and mostly understand what it is doing. Which I find useful as I may have another application in the future I can adapt this for

 

I have one question, as I do not understand why you have used 360/60/24 and not just 6/24 to get the 6 hour gain?

 

Thanks again

Paul

 
Posted : 23/01/2021 5:08 am
(@questvba)
Posts: 125
Estimable Member
 

Paul,

For the 360/60/24, there is no reason. It's just that at certain times the brain does certain things automatically.
You are absolutely right that we can also use 6/24.

BR,

Lionel

 
Posted : 23/01/2021 11:11 am
(@shep)
Posts: 7
Active Member
Topic starter
 

Ok thanks Lionel, just checking there wasn’t a reason for your doing that way. 
Thanks again for the solution, it will save many hours of work every month and improve accuracy

 

Paul

 
Posted : 23/01/2021 3:03 pm
(@shep)
Posts: 7
Active Member
Topic starter
 

Hi Lionel

I have just put the formula in my spreadsheet, back to the start of the year and found a problem with entries that are on a Saturday and Sunday, which all should return an answer which is Monday 15:00

Like Friday it should add the additional hours on from Monday as in the example below

Column A             Column B
16/01/2021 13:45 18/01/2021 15:00

17/01/2021 11:15  18/01/2021 15:00

All entries between 17:00 Friday and 08:00 Monday should return an answer which is Monday 15:00

I have added a second sheet with the problems highlighted yellow in your spreadsheet attached

 

Is it possible to fix this?

 

Thanks

 

Paul

 
Posted : 26/01/2021 6:11 am
(@questvba)
Posts: 125
Estimable Member
 

Hi Paul

Here is the adaptation for the WE. I added a column E (in green) with the new formula.

BR,

Lionel

 
Posted : 26/01/2021 11:11 am
(@shep)
Posts: 7
Active Member
Topic starter
 

Hi Lionel

Once again many thanks for your help

I have used your new formula with my data, back to the beginning of the year, it was all ok until I realised that Friday 1st January was a holiday and thus not a work day

I researched the WORKDAY.INTL function in the formula and found I could add the holiday dates into the formula, which I did but did not get the expected result

On sheet 2 of the attached spreadsheet the formula I used is in column G (blue) and the holidays listed in column J. The results that I think are wrong are highlighted yellow with the expected results next to them in column H

I think all entries between 31/12/2021 17:00 and 04/01/2021 09:00 should return an answer which is 04/01/2021 15:00

I have added a third sheet covering 01/04 to 08/04 to see what the results looked like over the weekend as both Friday 02/04 and Monday 05/04 are holidays, again there were unexpected results. The results that I think are wrong are highlighted yellow with the expected results next to them in column H

Is it possible to fix this

Also on your formula below, if the target was changed from 6 hours to:

5 hours, would I just need to change 60 to 72 and 15/24 to 14/24

4 hours, would I just need to change 60 to 90 and 15/24 to 13/24

=IF(WEEKDAY(B2,2)>5,WORKDAY.INTL((INT(B2)+17/24),1,1)+15/24,IF(B2<(INT(B2)+9/24),(INT(B2)+15/24),IF(B2>(INT(B2)+17/24),WORKDAY.INTL((INT(B2)+17/24),1,1)+15/24,IF((B2+360/60/24)>(INT(B2)+17/24),WORKDAY.INTL((INT(B2)+17/24),1,1)+9/24+MOD((B2+360/60/24)-(INT(B2)+17/24),1),B2+360/60/24))))

Thanks

Paul

 
Posted : 28/01/2021 11:01 am
(@questvba)
Posts: 125
Estimable Member
 

Hi Paul,

Here is an adaptation of the file taking into account the public holidays (which are on D2:D9). I have added an M column with the new results (which seem to be correct) on a new sheet (4).

You will see, the formula has been modified very slightly. This concerns the first condition where I check that the date is either a weekend day or a public holiday.

Still a little closer to perfection 😉

BR,

Lionel

 
Posted : 30/01/2021 10:21 am
(@shep)
Posts: 7
Active Member
Topic starter
 

Hi Lionel

Thanks for your patience in sorting this out for me

I have put your latest formula into my spreadsheet to the beginning of the year and everything looks good and hopefully will continue to

 

Thanks again

 

Paul

 
Posted : 02/02/2021 11:30 am
Share: