note 37832 modified in function.checkdate by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:54:14 +0000 |
| Subject: | note 37832 modified in function.checkdate by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79837@lists.php.net to get a copy of this message | ||
Example for count days between 2 dates.
<?php
$start = "20030101";
$end = "20031231";
function check($x){
return (strlen($x)==1?"0".$x:$x);
}
$count=0;
for($i = $start;$i<=$end;$i++){
$year = substr($i,0,4);
$mnd = substr($i,4,2);
$day = substr($i,6,2);
if(checkdate ($mnd,$day,$year)){
$count++;
}else{
if($mnd>12){
$mnd = "01";
$day = "00";
$year++;
}
if($day>=31){
$day = "00";
$mnd = check($mnd+1);
}
$i = $year.$mnd.$day;
}
}
echo $count;
?>
--was--
Example for count days between 2 dates.
$start = "20030101";
$end = "20031231";
function check($x){
return (strlen($x)==1?"0".$x:$x);
}
$count=0;
for($i = $start;$i<=$end;$i++){
$year = substr($i,0,4);
$mnd = substr($i,4,2);
$day = substr($i,6,2);
if(checkdate ($mnd,$day,$year)){
$count++;
}else{
if($mnd>12){
$mnd = "01";
$day = "00";
$year++;
}
if($day>=31){
$day = "00";
$mnd = check($mnd+1);
}
$i = $year.$mnd.$day;
}
}
echo $count;
http://php.net/manual/en/function.checkdate.php