Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP to calculate the number of office hours between two dates

Tags:

php

time

We run a service that's based on a 2 business day SLA, so if the request is submitted at 1pm on Monday it should be completed by 1pm of Wednesday.

So in the database I have two MySQL timestamps YYYY/MM/DD HH:MM:SS, and need some way of working out the time between the two dates in working time, based on office hours of 9am till 5pm.

Can anyone give me any ideas?

like image 920
Sjwdavies Avatar asked Jan 26 '10 10:01

Sjwdavies


1 Answers

The simplest way would be to store a table into your database with one line for each day, containing the working time available on that day. This lets you handle holidays and week-ends with high granularity, and you can get the amount of time available by running a sum over the days between the two dates specified by the user.

like image 107
Victor Nicollet Avatar answered Nov 15 '22 18:11

Victor Nicollet