PHP - Exclude all non-business hours / days from time difference

php, time, timestamp

Solution

The thing you have to do are 3 in numbers.

- You take your start date and calculate the rest time on this day (if it is a business day)

- You take your end date and calulate the time on this day and

- you take the days in between and multiply them with your business hours (just those, that are business days)

And with that you are done.

Find a little class attached, which does those things. Be aware that there is no error handling, time zone settings, daylight saving time, ...

input:

- start date

- end date

output:

- difference time in seconds

adjustable constants:

- Business hours

- Days that are not business days

Problem

I have a table which shows the time since a job was raised. ``` // These are unix epoch times... $raised = 1360947684; $now = 1361192598; $difference = 244914; ``` `$difference` needs to exclude any time outside of business hours (ex, 9-5 and weekends). How could I tackle this?

Original source