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
A Better Way to Replace Emoticons in PHP
Newline Not Working in PHP Mail
How to Require PHP Files Relatively (At Different Directory Levels)
Laravel Catch Eloquent "Unique" Field Error
How to Convert Arabic Characters to Unicode Using PHP
Zend Framework - Multiplate Navigation Blocks
How to Remove Exif from a Jpg Without Losing Image Quality
Speeding Up Large Numbers of MySQL Updates and Inserts
How to Keep a PHP Session Active Even If the Browser Is Closed
How to Increase by 1 All Keys in an Array
How to Add Filter or Hook for "Woocommerce_Add_To_Cart"
How to Make Ruby Aes-256-Cbc and PHP Mcrypt_Rijndael_128 Play Well Together
Sort Array Based on the Datetime in PHP
Function to Add Dashes to Us Phone Number in PHP
Php-Font-Lib Must Either Be Installed via Composer or Copied to Lib/Php-Font-Lib
How to Disable the Back Browser Button After User Press Logout and Destroy Session