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
Link to comment
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
[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.