Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Increment time by 15 minutes [closed]

In MySql database we have a column of type time and we need to increment the time by fifteen minutes in our php code.

For example time is 09:45:00, it should become 10:00:00

like image 840
ashwinbhy Avatar asked Jun 01 '26 18:06

ashwinbhy


2 Answers

You can fetch it directly from mysql itself:

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

For more information you can visit : http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

As per your comment if you want to do it in PHP, You can do like this:

$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
like image 198
Suresh Kamrushi Avatar answered Jun 03 '26 07:06

Suresh Kamrushi


how about doing this:

strtotime("+15 minutes" , time());

strtotime("+15 minutes" , strtotime( $this->time )); // suppose it's a string
like image 24
Developerium Avatar answered Jun 03 '26 06:06

Developerium