Time calculation in php (add 10 hours)?

myphpsql00 picture myphpsql00 · Nov 3, 2009 · Viewed 115.5k times · Source

I get the time:

$today = time();
$date = date('h:i:s A', strtotime($today));

if the current time is "1:00:00 am", how do i add 10 more hours to become 11:00:00 am??

Answer

Amber picture Amber · Nov 3, 2009

strtotime() gives you a number back that represents a time in seconds. To increment it, add the corresponding number of seconds you want to add. 10 hours = 60*60*10 = 36000, so...

$date = date('h:i:s A', strtotime($today)+36000); // $today is today date

Edit: I had assumed you had a string time in $today - if you're just using the current time, even simpler:

$date = date('h:i:s A', time()+36000); // time() returns a time in seconds already