We have 16 guests online
   
PHP Scripts arrow Free PHP Tutorials arrow Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP 
Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP

Date Compare
User Rating: / 1
PoorBest 

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.

  1. <?php
  2. // returns <0, 0, >0 if  date a< date b,date a== date b,date a > date b respectively.
  3. function compareDate ($i_sFirstDate, $i_sSecondDate)
  4. {
  5.  //Break the Date strings into seperate components
  6.         $arrFirstDate = explode ("/", $i_sFirstDate);
  7.         $arrSecondDate = explode ("/", $i_sSecondDate);
  8.  
  9.         $intFirstDay    = $arrFirstDate[0];
  10.         $intFirstMonth  = $arrFirstDate[1];
  11.         $intFirstYear   = $arrFirstDate[2];
  12.  
  13.         $intSecondDay   = $arrSecondDate[0];
  14.         $intSecondMonth = $arrSecondDate[1];
  15.         $intSecondYear  = $arrSecondDate[2];
  16.  
  17.  
  18.     // Calculate the diference of the two dates and return the number of days.
  19.    
  20.                      
  21.         $intDate1Jul = gregoriantojd($intFirstMonth, $intFirstDay, $intFirstYear);
  22.         $intDate2Jul = gregoriantojd($intSecondMonth, $intSecondDay, $intSecondYear);
  23.            
  24.         return  $intDate1Jul - $intDate2Jul;
  25.        
  26. }//end Compare Date
  27. ?>

 

 

Directory Stats

There are 684 listing and 43 categories in our website

Change Language

Debt Consolidation Loans
Home Loan
Flights
Personal Finance
Consolidation Loans