Skip to main content

Posts

Showing posts from September, 2018

Business hours calculation using PHP

Most of ticketing alert projects needed SLA calculation to exclude holidays and weekends or Off business hours. First of all, let us take a look at types of SLA we need to calculate. For instance, few companies will work 24/7 shifts and 8x5, 8x7 etc. So we need to consider business hours. In this example, I'm considering business hours which starts at 09:00 AM and ends at 06:00 PM. Also, using this code we can calculate 24/7 too. Let's consider business hours started at 9:00 AM to 18:00 PM without weekends. Now, take the actual work start period and end period.                                                       Demo <?php $incident_work_started = '2018-09-12 09:28:07'; $incident_work_ended = '2018-09-19 17:45:00'; $totalHours = round(get_working_hours($incident_work_started,$incident_work_ended),2)."\n"; echo "Total hours: ".$totalHours; function get_working_hours($work_started,$work_ended) { //