Adding 1 hour to time variable
This simple thing has wasted hours of my time trying to get it working, still havnt worked it out...
i have
$time = '10:09';
I want to add an hour to that...
So, I've tried:
$time = strtotime('+1 hour');
strtotime('+1 hour', $time);
$time = date('H:i', strtotime('+1 hour'));
None of the above worked.
Can you guys help me out?
Thanks.
3Answer
Worked for me..
$timestamp = strtotime('10:09') + 60*60;
$time = date('H:i', $timestamp);
echo $time;//11:09
- answered 8 years ago
- Gul Hafiz
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'));
- answered 8 years ago
- Gul Hafiz
You can use:
$time = strtotime("10:09") + 3600;
echo date('H:i', $time);
Or date_add
: http://www.php.net/manual/en/datetime.add.php
- answered 8 years ago
- B Butts
Your Answer