Computing.Net > Forums > Web Development > getting new date from existing date and time

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

getting new date from existing date and time

Reply to Message Icon

Name: BigShow
Date: September 20, 2009 at 21:14:08 Pacific
OS: Windows XP
CPU/Ram: pentium 4
Product: Dell / Lap top
Subcategory: PHP
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: September 21, 2009 at 12:50:11 Pacific
Reply:

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).

<?php

   $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.

HTH


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: getting new date from existing date and time

Need some peoples opinions www.computing.net/answers/webdevel/need-some-peoples-opinions/2005.html

new site design www.computing.net/answers/webdevel/new-site-design/300.html

Php date www.computing.net/answers/webdevel/php-date/395.html