note 78860 deleted from function.mcal-date-compare by philip
| From: | philip@php.net | Date: | Tue, 27 May 2008 00:26:01 +0000 |
| Subject: | note 78860 deleted from function.mcal-date-compare by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139824@lists.php.net to get a copy of this message | ||
Note Submitter: nepnep_ at hotmail dot com
----
/* this is much a much better code */
/* a very short one and easy to understand */
/* reurns -1 if first given date is lower than the second */
/* reurns 0 if given dates are equal */
/* reurns 1 if second given date is lower than the first */
function date_compare($y1,$m1,$d1,$y2,$m2,$d2){
/* check the year */
if($y1 > $y2){
/* if $y1 is greater then therefore the first date is greater than second */
return 1;
}elseif($y1 == $y2){
/* equal year, check the month */
if($m1 > $m2){
/* year is equal but the first given month is greater
/* therefore the first given date is greater */
return 1;
}elseif($m1 == $m2){
/* if month are also equal, check the date */
if($d1 > $d2){
return 1;
}elseif($d1 == $d2){
return 0;
}else{
return -1;
}
}else{
/* if year is equal but month is less, therefore the first given date is less */
return -1;
}
}else{
/* if $y1 is less than $y2 */
return -1;
}
}