在日期/时间字段中添加日期和时间,并使用mysql获取php中的更新日期/时间 [英] add days and hours in date/time field and get the updated date/time in php using mysql
本文介绍了在日期/时间字段中添加日期和时间,并使用mysql获取php中的更新日期/时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提供用户提交 datetime
值的能力,以及代表额外的天数/小时的值,然后存储 datetime
,这是通过将两个添加到mysql数据库中的。
I would like to provide the ability for users to submit a datetime
value, along with values representing additional days/hours, and then store the datetime
that results from adding the two in a mysql database.
推荐答案
在PHP中,这应该有助于:
If you want to do it in PHP, this should help:
$datetime = '2010-02-11 12:00:00';
$days = '5';
$hours = '3';
$new_datetime = date('Y-m-d H:i:s', strtotime("+$days days $hours hours", strtotime($datetime)));
echo $new_datetime; # Will output '2010-02-16 15:00:00'
这篇关于在日期/时间字段中添加日期和时间,并使用mysql获取php中的更新日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文