• support@answerspoint.com

Adding 1 hour to time variable

2206

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


0

Worked for me..

$timestamp = strtotime('10:09') + 60*60;

$time = date('H:i', $timestamp);

echo $time;//11:09
  • answered 8 years ago
  • Gul Hafiz

0

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

0

You can use:

$time = strtotime("10:09") + 3600;
echo date('H:i', $time);

Or date_addhttp://www.php.net/manual/en/datetime.add.php

  • answered 8 years ago
  • B Butts

Your Answer

    Facebook Share        
       
  • asked 8 years ago
  • viewed 2206 times
  • active 8 years ago

Best Rated Questions