添加时间PHP

时间:2013-02-19 19:06:09

标签: php

我正在尝试使用这些变量中捕获的开始时间和结束时间。我想将这些值加在一起,以便在variouse任务上花费总时间。所以我得到了这些价值观,并试图做这样的事情:

//start times
$time_1 = $_POST['start_of_service_1'];
$time_2 = $_POST['start_of_service_2'];
$time_3 = $_POST['start_of_service_3'];

//end times
$etime_1 = $_POST['end_of_service_1'];
$etime_2= $_POST['end_of_service_2'];
$etime_3 = $_POST['end_of_service_3'];

//total hours
$tot_hours_1 = date('H:i',strtotime($etime_1)-strtotime($time_1);
$tot_hours_2 = date('H:i',strtotime($etime_2)-strtotime($time_2));
$tot_hours_3 = date('H:i',strtotime($etime_3)-strtotime($time_3));

$totaltime = $tot_hours_1 + $tot_hours_2 + $tot_hours_3

因此,如果时间跨度为5分钟,则为00:05 + 00:05 + 00:05 = 00:15分钟。

这些时间功能看起来很棘手我遇到了可怕的麻烦和时间来克服这个障碍。

有人可以就如何做到这一点给我建议吗?

2 个答案:

答案 0 :(得分:2)

只需删除date('H:i',和相应的)即可。这将为您留下可以加在一起的数字。使用date()格式化应该是 last 的事情。

答案 1 :(得分:0)

您正尝试在此行date formats中添加$totaltime = $tot_hours_1 + $tot_hours_2 + $tot_hours_3。无法使用Time添加+格式。尝试添加纯数字,然后使用date()格式化。