问题
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