我已将日期和时间存储在数据库中2015-06-31 14:00
我希望通过变量向hours
字段添加一些date
如何添加
<?php
//set an date and time to work with
$start = '2015-06-31 14:00';
$hours='05:00';
//display the converted time
echo date('Y-m-d H:i',strtotime("+{$hours} hours",strtotime($start)));
?>
答案 0 :(得分:0)
检查
//set an date and time to work with
$start = '2015-06-30 14:00';
$hours= 5;
//display the converted time
echo date('Y-m-d H:i',strtotime("+{$hours} hours",strtotime($start)));
输出为2015-06-30 19:00
答案 1 :(得分:0)
试试这个
<?php
$start = '2015-10-31 14:00';
$hours = '05:00';
$date = new DateTime($start);
$date->modify(sprintf("+%d hours", $hours));
echo $date->format("Y-m-d H:i");
?>
<强>输出:强>
2015-10-31 19:00