我有例如:
$first = '2014-05-18 12:00:00';
$last = '2014-05-18 13:30:00';
我想在这些日期计算30分钟的间隔。 对于此示例,interval = 3。
其他例子:
$first = '2014-05-18 11:00:00';
$last = '2014-05-18 14:00:00';
interval = 6;
PHP中最好的方法是什么?
答案 0 :(得分:1)
答案 1 :(得分:0)
function timeDiff30minutes($first,$last){
$first = new Datetime($first);
$last = new Datetime($last);
$time_diff = $first->diff($last);
$time_diff_minute = $time_diff->days * 24 * 60;
$time_diff_minute += $time_diff->h * 60;
$time_diff_minute += $time_diff->i;
return $time_diff_minute/30;
}
timeDiff30minutes('2014-05-18 11:00:00','2014-05-18 14:00:00') // output 6