RE: [PHP] Problem with strtotime() and 2002-03-31

From: Date: Fri, 22 Mar 2002 14:05:07 +0000
Subject: RE: [PHP] Problem with strtotime() and 2002-03-31
Groups: php.general 
Request: Send a blank email to php-general+get-89681@lists.php.net to get a copy of this message
> -----Original Message----- > From: John Clarke [mailto:jclarke@premierstateliner.com.au] > Sent: 20 March 2002 00:40 > > I have used the following script successfully for a year now, > but have just > found a problem with the date 2002-03-31. > > Any ideas why this would be happening? > > function addDays($date,$nofdays) { > $dd=strtotime($date); > $dd2=$dd + (3600*24*$nofdays); > return date("Y-m-d", $dd2); > } > $nd=addDays("2002-03-31","2"); > echo $nd This will be, indeed, an issue with the daylight-saving time transition which, at least hereabouts, occurs on 31-March/2002. But, since you're using strtotime anyway, why don't you just use its relative offset capabilities to do your conversion: function addDays($date,$nofdays) { $dd2 = strtotime("+$nofdays days", $date); return date("Y-m-d", $dd2); } Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#89681) next »