"David Nicholson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hello,
This is a reply to an e-mail that you wrote on Wed, 30 Jul 2003 at
19:18, lines prefixed by '>' were originally written by you.
> If I have:
> $firstdate = "2003-06-28";
> then how can I get $firstdate plus 4 days?
> Thanks!
date("Y-d-m",mktime(0,0,0,substr($firstdate,5,2),substr($firstdate,8,2),subs
tr($firstdate,0,4))
+ (60*60*24*4));
Should do the trick, you can probably use strtotime instead of all
the substr()'s but at a guess I would expect the above to be quicker
(not that I have benchmarked it).
HTH
David.
--------------------------------------------------
David's reply was spot on but I thought I'd break it down for you in case
you didn't understand...
$firstdate = "2003-06-28";
// Parse the date
list($year, $month, $day) = explode("-", $firstdate);
// Get the timestamp for this date..
$ts = mktime(0,0,0,$month,$day,$year);
// Add four days to timestamp..
$ts += 345600;
// Get year, month, day for new date..
$newdate = date("Y-m-d", $ts);
The only thing that I'm doing differntly is the way in which I'm parsing the
date. I'm using the list()=explode() method as opposed to substr() becuase
this method is not prone to fail when values are not zero filled.
Good luck,
Kevin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php