Jump to content


This topic is now archived and is closed to further replies.


Work out time by adding years, days, hours etc

Recommended Posts


I want to work out what the time would be if I was to add a variety of time amounts to it.

Basically I want to take the current time using the time() function and add to it x years, x months, x days, x hours and x minutes.

Each of thesewill be held in a variable. For example $numdays will hold the number of days to add to the current time.


Share this post

Link to post
Share on other sites
you would be better off using strtotime and date() for what you want they are more flexible than time() for manipulating time and days etc.

you could then
$now = strtotime("now");
$timenow  =  date("H:i:s", $now);    // 17:15:00 i.e. 15 minutes past 5 in the evening
$timenew =  date("H:i:s", (strtotime("+2 day", $now)));  //15 minutes past 5 in the evening two days in the future

read the strtotime manual <a href="http://uk2.php.net/manual/en/function.strtotime.php"> Here </a> and the date manual <a href="http://uk2.php.net/manual/en/function.date.php"> Here </a> for more details.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.