How to Add 5 Minutes to Current Datetime on PHP < 5.3

How to add 5 minutes to current datetime on php 5.3

$date = '2011-04-8 08:29:49';
$currentDate = strtotime($date);
$futureDate = $currentDate+(60*5);
$formatDate = date("Y-m-d H:i:s", $futureDate);

Now, the result is 2011-04-08 08:34:49 and is stored inside $formatDate

Enjoy! :)

PHP Date Time Current Time Add Minutes

I think one of the best solutions and easiest is:

date("Y-m-d", strtotime("+30 minutes"))

Maybe it's not the most efficient but is one of the more understandable.

php: how to add minutes to timestamp

You could use strtotime() like this:

$date = date('Y-m-d H:i:s', strtotime('now +60 minutes'));

Which would give you the date 60 minutes in the future formatted the way you'd like.

Adding minutes to date formatting syntax

Use the DateTime class, it's easier to work with:

$eventdate = \DateTime::createFromFormat('Y/m/d h:i:s', $eventdate);
$eventdate->modify('+480 minutes');

echo $eventdate->format('Y/m/d h:i:s');

PHP: Adding time to current time?

Close, you want:

$new_time = date('H:i', strtotime('+15 minutes'));

Adding 30 minutes to time formatted as H:i in PHP

$time = strtotime('10:00');
$startTime = date("H:i", strtotime('-30 minutes', $time));
$endTime = date("H:i", strtotime('+30 minutes', $time));

NOW() function in PHP

You can use the date function:

date("Y-m-d H:i:s");

handling time format in mysql and php

If you want to update your sql table, you can use the DATE_ADD function:

UPDATE table SET time = DATE_ADD(time, INTERVAL 5 MINUTE)

If you want to add 5 minutes to a timestamp in PHP you can use the function strtotime:

$time = $time + strtotime("+5 minutes");

If your time is a string (ie in format 14:55:00), you can do the following:

$timeAsString = "14:55:00";
$timestamp = strtotime("+5 minutes", strtotime($timeAsString));
$time = date("H:i:s", $timestamp);

echo $time;

How to get time difference in minutes in PHP

Subtract the past most one from the future most one and divide by 60.

Times are done in Unix format so they're just a big number showing the number of seconds from January 1, 1970, 00:00:00 GMT

How to minus 5 minutes from System Date in PHP?

In objective style, you can use method sub and DateInterval object:

$date = new DateTime(null, new DateTimeZone('Asia/Kolkata'));

echo $date->format('H:i:s').PHP_EOL;
$date->sub(new DateInterval('PT5M'));
echo $date->format('H:i:s').PHP_EOL;

result:

17:44:04
17:39:04


Related Topics



Leave a reply



Submit