考虑到日期和时间,我想将那个小时附加到该日期。
E.g:给出小时3和日期2017-05-30我想:2017-05-30 03:00:00
<?php
$d1 = date('Y-m-d');
$hour = 3;
$new_time = date("Y-m-d H:i:s", strtotime('+' . $hour .' hours', $d1));
echo $new_time;
?>
运行以下代码时,我得到:
注意:$ new_time =遇到一个格式不正确的数值 日期(“Y-m-d H:我:s ......
如何获得正确的输出?
答案 0 :(得分:1)
尝试使用+小时的strtotime(),如下所示:
<?php
$d1 = date('Y-m-d');
$new_time = date("Y-m-d H:i:s", strtotime($d1."+ 3 hour")); //here you can change the hour according to your need as now it is + 3
echo $new_time;
答案 1 :(得分:0)
答案 2 :(得分:0)
您只需按strtotime($time) + $yourtimeinseconds;
这里是Eval Link
代码:
<?php
$time = date("Y-m-d H:i:s");
$hour = 3*60*60; // To Seconds
$time = strtotime($time) + $hour; // Add 1 hour
$time = date('Y-m-d H:i:s', $time);
echo $time;
答案 3 :(得分:0)
如果您想要从当前时间开始3小时,则所有其他答案都适用。如果你只想要凌晨3点,那就加上时间,不需要数学。
SELECT zones.zoneName
, customers.customerName
, products.productName
, SUM(amount) AS amount
FROM customers
INNER JOIN zones
ON customers.zoneId = zones.zoneId
LEFT JOIN sales
ON customers.customerId = sales.customerId
LEFT JOIN products
ON sales.productId = products.productId