Jump to content


Photo

Work out time by adding years, days, hours etc


  • Please log in to reply
1 reply to this topic

#1 Pythondesigns

Pythondesigns
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 20 September 2006 - 04:46 PM

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

#2 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 20 September 2006 - 06:59 PM

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/m...strtotime.php"> Here </a> and the date manual <a href="http://uk2.php.net/m...tion.date.php"> Here </a> for more details.

you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users