Saturday, September 24, 2011

Adding 1 Hour to PHP Time

Here i am writing an example for adding 1 hour to any time. for this we need to convert the time or date to UNIX time like as in this code
$starttime = strtotime('09:00AM');
$endtime = strtotime('05:00PM');
while ($endtime >= $starttime) {
echo date('ga', $starttime).'<br>';
$starttime = $starttime + 3600;

in the above code i am adding 3600 to $starttime which is equal to 1 Hour(60*60), So the way you want to make any increment just add that much seconds.