note 93972 added to function.strtotime

From: Date: Fri, 09 Oct 2009 07:38:25 +0000
Subject: note 93972 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-161581@lists.php.net to get a copy of this message
lot of people said that there is bug in strtotime method like given in this example: echo date( "Y-m-d", strtotime( "2009-01-31 +1 months" ) )."<br>"; this gives 03-03-2009 instead of 28-02-2009 here is work arround for this bug. /// n=no of months , $y =year, $m = month, $d = day , $t = + or - function NewMonthDate($n,$y,$m,$d,$t) { for($i=1; $i <= $n; $i++) { if($t=="+") { $pmonth=$m+$i; } if($t=="-") { $pmonth=$m-$i; } $pyear=$y; $aa=1; /////////////////this will show lastmonth////////////// $lastmonth = mktime(0, 0, 0, $pmonth, $aa, $pyear); $smonth=date("m",$lastmonth); $syear=date("Y",$lastmonth); $ndays=date("t",$lastmonth); $valarray=array($smonth,$syear,$ndays); $mm=$mm+$ndays; } $basedate="$pyear-$m-$d"; $date2 = strtotime("$basedate $t$mm days"); $date1=date("d-m-Y",$date2); return $date1; } //// $n=1; $y=2009; $m=01; $d=31; $t="+"; $rr=NewMonthDate($n,$y,$m,$d,$t); print_r($rr); ---- Server IP: 69.147.83.197 Probable Submitter: 58.65.162.13 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/93972 Del: integrated -- https://master.php.net/note/delete/93972/integrated Del: useless -- https://master.php.net/note/delete/93972/useless Del: bad code -- https://master.php.net/note/delete/93972/bad+code Del: spam -- https://master.php.net/note/delete/93972/spam Del: non-english -- https://master.php.net/note/delete/93972/non-english Del: in docs -- https://master.php.net/note/delete/93972/in+docs Del: other reasons-- https://master.php.net/note/delete/93972 Reject -- https://master.php.net/note/reject/93972 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161581) next »