note 93972 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 14 Dec 2014 11:33:08 +0000 |
| Subject: | note 93972 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201162@lists.php.net to get a copy of this message | ||
Note Submitter: flexibill2001 at hotmail dot com
----
lot of people said that there is bug in strtotime method like given in this example:
<?php 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.
<?php
/// 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);
?>