Call us Toll-Free:
1-800-218-1525
Email us

 Sponsors

Date Compare

Code Wizard, 12-30-2006

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.

// 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
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions