Adding 1 hour to time variable
Worked for me..
$timestamp = strtotime('10:09') + 60*60;
$time = date('H:i', $timestamp);
echo $time;//11:09
Explanation:
strtotime('10:09')
creates a numerical timestamp in seconds, something like 1510450372
. Simply add or remove the amount of seconds you need and use date()
to convert it back into a human readable format.
$timestamp = strtotime('10:09') + 60*60; // 10:09 + 1 hour
$timestamp = strtotime('10:09') + 60*60*2; // 10:09 + 2 hours
$timestamp = strtotime('10:09') - 60*60; // 10:09 - 1 hour
time()
also creates a numerical timestamp but for right now. You can use it in the same way.
$timestamp = time() + 60*60; // now + 1 hour
You can do like this
echo date('Y-m-d H:i:s', strtotime('4 minute'));
echo date('Y-m-d H:i:s', strtotime('6 hour'));
echo date('Y-m-d H:i:s', strtotime('2 day'));