วันพุธ, ธันวาคม 14, 2548

Date Comparison (on PHP)
using gregoriantojd()
// returns <0, 0, >0 if date a< date b,date a== date b,date a > date b respectively.
function compareDate ($FirstDate, $SecondDate)
{
//Break the Date strings into seperate components
$aFirstDate = explode ("/", $FirstDate);
$aSecondDate = explode ("/", $SecondDate);

$iFirstDay = $aFirstDate[0];
$iFirstMonth = $aFirstDate[1];
$iFirstYear = $aFirstDate[2];

$iSecondDay = $aSecondDate[0];
$iSecondMonth = $aSecondDate[1];
$iSecondYear = $aSecondDate[2];


// Calculate the diference of the two dates and return the number of days.
// Converts a Gregorian date to Julian Day Count
//

$iDate1Jul = gregoriantojd($iFirstMonth, $iFirstDay, $iFirstYear);
$intDate2Jul = gregoriantojd($iSecondMonth, $iSecondDay, $iSecondYear);

return $iDate1Jul - $iDate2Jul;

}//end Compare Date
echo compareDate ("01/03/2003","01/02/2003");
?>

1 ความคิดเห็น:

ziddik::zdk กล่าวว่า...

วันนี้ post ผ่าน GNOME BLOG ไม่ได้แฮะ....เป็นงง..เมื่อวานได้...วันนี้ไม่ได้...