简体   繁体   English

在php中添加1小时的mysql时间戳

[英]Add 1 hour on mysql timestamp in php

In my Mysql table I have a timestamp field. 在我的Mysql表中,我有一个时间戳字段。 In my php page I show the record ($row[data]) in this way 在我的php页面中,我以这种方式显示记录($ row [data])

echo date("d-m-Y H:i:s", strtotime($row['data']));

Now in my php I'd like to add 1 hour on my date. 现在在我的PHP中我想在我的约会时加1小时。 How can I do this? 我怎样才能做到这一点? Thanks 谢谢

echo date("d-m-Y H:i:s", strtotime($row['data'])+3600);

note that you can't compare resulting dates in "dmY" format. 请注意,您无法比较“dmY”格式的结果日期。

either compare strtotime results or initial dates. 比较strtotime结果或初始日期。 or format your results into proper format first. 或者首先将结果格式化为正确的格式。

You could do this straight away in MySQL: 您可以在MySQL中立即执行此操作:

SELECT `date` + INTERVAL 1 HOUR AS `date`
FROM ...

试试:

strtotime($row['data'] . ' +1 hour')
echo date("d-m-Y H:i:s", strtotime($row['data']) + 3600);

只需手动添加时间(3600秒= 1小时)。

加3600秒你会没事的。

echo date("d-m-Y H:i:s", strtotime($row['data'])+3600);
         echo date("d-m-Y H:i:s", strtotime($row['data'].' +1 hour'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM