getting new date from existing date and time

Dell / Lap top
September 20, 2009 at 21:14:08
Specs: Windows XP, pentium 4
Hi Guys, this function im trying to write is driving me up a wall. I have a startdate in my database (yyyy-mm-dd) and a duration (30 days), I am trying to get the new date based on these variables. The actual date varies. This is one of those things that should be simple but I have been coding for 12 hours and cant make sense of it. Any thoughts?

See More: getting new date from existing date and time

Report •

September 21, 2009 at 12:50:11
Something like below may do; however, IIRC, the time / date functions rely on the correct server time, leap years, and the EST - EDT time change (if observed).


   $dbtime = date('Y-m-d', time());
   list($year, $mon, $day) = sscanf($dbtime, '%4d-%2d-%2d');
   $newt = mktime(0, 0, 0, $mon, $day, $year) + (3600 * 24 * 30);

   echo "dbtime = " . $dbtime;
   echo "<br />new time = " . date('Y-m-d', $newt);

It *may* also be easier to use a varchar or bigint to store the time in the database instead of using the TIMEDATE or similar db functions... that way, you'd start out with an int instead of a formatted string.


Report •
Related Solutions

Ask Question