Share on Google+Share on Google+

PHP Date add 1 hour

Advertisement
In this example code we will show you how you can add 1 hour to a date in PHP code. In this session you will be learn how you can add one hour to a date object.

In the following example code we are showing how you can add one hour to a date object.

<?php

//This PHP Example code shows how to add one hour to a date object

$todayDate = date("Y-m-d g:i a");// current date
$currentTime = time($todayDate); //Change date into time

//echo "<br>".$currentTime;
//Add one hour equavelent seconds 60*60

$timeAfterOneHour = $currentTime+60*60;

/echo "<br>".$timeAfterOneHour;
echo "<br>Current Date and Time: ".date("Y-m-d H:i:s",$currentTime);
echo "<br>Date and Time After adding one hour: ".date("Y-m-d H:i:s",$timeAfterOneHour);

?>

Output of the program:

Current Date and Time: 2009-08-27 10:55:48
Date and Time After adding one hour: 2009-08-27 11:55:48

 

 

Advertisements

Posted on: August 27, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.