Jump to content

Work out time by adding years, days, hours etc


Pythondesigns

Recommended Posts

Hello,

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.

Thanks
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
[code]
$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
[/code]

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.

Archived

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

×
×
  • Create New...

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.