在日期/时间字段中添加日期和时间,并使用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'