|
The following function compares two dates in the dd/mm/yyyy format.
It uses the PHP function gregoriantojd() as mktime() is unreliable for
dates < 1970. The mcal_date_compare also relies on the mcal libraries being installed.
One improvement could be a third parameter passed in with the actual date format to be used.
-
<?php
-
// returns <0, 0, >0 if date a< date b,date a== date b,date a > date b respectively.
-
function compareDate ($i_sFirstDate, $i_sSecondDate)
-
{
-
//Break the Date strings into seperate components
-
$arrFirstDate = explode ("/", $i_sFirstDate);
-
$arrSecondDate = explode ("/", $i_sSecondDate);
-
-
$intFirstDay = $arrFirstDate[0];
-
$intFirstMonth = $arrFirstDate[1];
-
$intFirstYear = $arrFirstDate[2];
-
-
$intSecondDay = $arrSecondDate[0];
-
$intSecondMonth = $arrSecondDate[1];
-
$intSecondYear = $arrSecondDate[2];
-
-
-
// Calculate the diference of the two dates and return the number of days.
-
-
-
$intDate1Jul = gregoriantojd($intFirstMonth, $intFirstDay, $intFirstYear);
-
$intDate2Jul = gregoriantojd($intSecondMonth, $intSecondDay, $intSecondYear);
-
-
return $intDate1Jul - $intDate2Jul;
-
-
}//end Compare Date
-
?>
|