How to calculate time difference with schedule working b/w two time stamps?

对着背影说爱祢 提交于 2020-01-24 16:58:28

问题


Here is the scenario that i have a table of task start_time and end_time like this, On start method i note start_time and On pause/in review/done i note the end_time here is my table

ID    |    task_id       |    start_time      |     end_time
-----------------------------------------------------------------
1             1           2017-03-02 06:27:28   2017-03-12 10:43:37
2             5           2017-03-02 07:16:05          NULL//in progress no end time  

for example there are shifting hours from 6 to 10 and working days in week i want to calculate exact time during shifting hours in working days. I have searched a lot to find the answer please help me with a proper calculation method.

Note: where end_time is NULL there i use date() means current date


回答1:


PHP code demo

<?php

$datetime1 = new DateTime('2017-03-02 06:27:28');
if($datetime1->format("D")!="Sun" && $datetime1->format("D")!="Sat")
{
    $datetime2 = new DateTime('2017-03-12 10:43:37');
    $interval = $datetime1->diff($datetime2);
    echo $interval->format('%H:%I:%s');
}


来源:https://stackoverflow.com/questions/43047820/how-to-calculate-time-difference-with-schedule-working-b-w-two-time-stamps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!