Location: PHPKode > scripts > Date Compare > date-compare/DateAdd.class.php
<?php

/**
* +------------------------------------------------------------------------------+
* Author(s): Gobinath
* +------------------------------------------------------------------------------+
* Date Manipulation Class
* Explanation: purpose of this class is compare two dates & get the next month date
*/

class DateCK{
 

    //Variable Decleration 
            var $splitDate;
            var $Month;
            var $Day;
            var $Year;
            var $MonthDay;

    var $resultDate;
    var $DateSeperator;
    var $DateFormat;

            

    function DateCK($date,$dateFormat,$strSeperator){
               $this->MonthDay=array(31,28,31,30,31,30,31,31,30,31,30,31);
               $this->DateSeperator = $strSeperator;
               $this->DateFormat = $dateFormat;
               $this->splitDate = array();    // 
               $this->splitDate = explode($strSeperator,$date);
               if (strcasecmp($dateFormat, "m d y") == 0){
                  $this->Month = $this->splitDate[0];
                  $this->Day = $this->splitDate[1];
                  $this->Year = $this->splitDate[2]; 
               }
               if (strcasecmp($dateFormat,  "d m y") == 0){
                          $this->Day = $this->splitDate[0];
                          $this->Month = $this->splitDate[1];
                          $this->Year = $this->splitDate[2]; 
               }
               if (strcasecmp($dateFormat, "y m d") == 0){
                          $this->Year = $this->splitDate[0]; 
                          $this->Month = $this->splitDate[1];
                          $this->Day = $this->splitDate[2];
               }           
    } // Constructor Ends Here

           

   function MonthDate($Type){
     // Purpose to Calculate and return the Values of next month
       if(strcasecmp($Type, "Month") == 0 ){
            $this->Month += 1;
            if ($this->Month >= 13){
                  $this->Month = 1;
                  $this->Year += 1;
            }
        }
        if (strcasecmp($this->DateFormat, "m d y") == 0){
                       $tmpDate = $this->Month.$this->DateSeperator.str_replace("-","",$this->Day).$this->DateSeperator.$this->Year;
        }
        if (strcasecmp($this->DateFormat,  "d m y") == 0){
                        $tmpDate = str_replace("-","",$this->Day).$this->DateSeperator.$this->Month.$this->DateSeperator.$this->Year;
        }                  
        if (strcasecmp($this->DateFormat,  "y m d") == 0){
                        $tmpDate = $this->Year.$this->DateSeperator.$this->Month.$this->DateSeperator.str_replace("-","",$this->Day);
        }                                            
        return $tmpDate;
   } // MonthDate Function Ends Here

	function DateCheck(){
        // Get Server Date
		//Returns True if the your date is greater than server date
		//Return false if your date is less than server date
        $NOW=getdate();
		$Month= $NOW[mon];
		$Year = $NOW[year];
		$Day = $NOW[mday];
        if($this->Year > $Year){
		      return true;
  	    }
		else{
            if($this->Month > $Month){
				 return true;
			} 
			else{
			    if($this->Day > $Day){
				    return true;
				}
				else{
				    return false;
				}
			}
		}     
    }
	
}

?>
Return current item: Date Compare