如何将时间增加 15 分钟


How to Increment time by 15 minutes

MySql数据库中,我们有一列时间类型,我们需要在 php 代码中将时间增加 15 分钟。

例如,时间是 09:45:00,它应该变成 10:00:00

你可以直接从 mysql 本身获取它:

Select DATE_ADD('09:45:00', INTERVAL 15 MINUTE) as updatetime from tableName

欲了解更多信息,请访问:http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

根据您的评论,如果您想在 PHP 中执行此操作,您可以这样做:

$date = new DateTime('09:45:00');
$date->add(new DateInterval('PT15M'));
echo $date->format('h:i:s') . "'n";  //it i will give you 10:00:00
这样做

怎么样:

strtotime("+15 minutes" , time());
strtotime("+15 minutes" , strtotime( $this->time )); // suppose it's a string