Home     Articles & Projects     Products & Web Services     Forum

Add minutes,hours,days on a date

Hi david
Im a new member in this Forum i found out about your forum via google when searching for php & javascript coding. Im a portuguese student and Im currently working in my project based on web strategy game, my problem is in having a mysql value that represent a number of seconds needed to build or produce a unit this number of seconds represents the amount of time needed to build a structure, i need to pass this number of seconds into a valid date that would represent seconds,minutes,hours and days.
Here is an example:
Sun Jun 22 16:13:59 2008 + 12 days 2hours 7minutes 1 second = Sun Jul 4 18:15:00 2008

Does any1 have any thoughts or ideas i could follow?

Hi there! Are you aware that

Hi there!

Are you aware that PHP's strtotime() function supports relative timings, for example:

<?php
  $thisTimeTomorrow
= strtotime("+1 day");
?>

However in your case, it sounds like it is more a case of simply adding second values together and using the date() function to print the resulting time. For example:

<?php
  $timeToBuildStructure
= 7200; // seconds, from database
 
$now = time(); // current time (seconds since 1/1/1970)
 
$finishedBuilding = $now + $timeToBuildStructure;
  print
date("D M j H:i:s Y",$finishedBuilding);
?>

Hope this helps!
Cheers,
David.