note 84738 modified in function.date by thiago
| From: | thiago@php.net | Date: | Mon, 28 Jul 2008 16:30:03 +0000 |
| Subject: | note 84738 modified in function.date by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142858@lists.php.net to get a copy of this message | ||
if you want to get the number of month
between two dates
you can use this function:
<?php
/*
$start = "YYYYMM" ;
$stop = "YYYYMM" ;
*/
function getNumMonth($start,$stop) {
$aSta = substr($start,0,4) ;
$aSto = substr($stop,0,4) ;
$mSta = substr($start,4,2) ;
$mSto = substr($stop,4,2) ;
if($aSta == $aSto) {
return $mSto-$mSta+1 ;
} else {
if(($aSto-$aSta) == 1) {
return 12-$mSta+$mSto+1 ;
} else {
return (12-$mSta+$mSto+1)+($aSto-$aSta-1)*12;
}
}
}
?>
--was--
if you want to get the number of month
between two dates
you can use this function:
/*
$start = "YYYYMM" ;
$stop = "YYYYMM" ;
*/
function getNumMonth($start,$stop) {
$aSta = substr($start,0,4) ;
$aSto = substr($stop,0,4) ;
$mSta = substr($start,4,2) ;
$mSto = substr($stop,4,2) ;
if($aSta == $aSto) {
return $mSto-$mSta+1 ;
} else {
if(($aSto-$aSta) == 1) {
return 12-$mSta+$mSto+1 ;
} else {
return (12-$mSta+$mSto+1)+($aSto-$aSta-1)*12;
}
}
}
http://php.net/manual/en/function.date.php