/* this is much a much better code */
/* a very short one and easy to understand */
/* reurns -1 if first given date is lower than the second */
/* reurns 0 if given dates are equal */
/* reurns 1 if second given date is lower than the first */
function date_compare($y1,$m1,$d1,$y2,$m2,$d2){
/* check the year */
if($y1 > $y2){
/* if $y1 is greater then therefore the first date is greater than second */
return 1;
}elseif($y1 == $y2){
/* equal year, check the month */
if($m1 > $m2){
/* year is equal but the first given month is greater
/* therefore the first given date is greater */
return 1;
}elseif($m1 == $m2){
/* if month are also equal, check the date */
if($d1 > $d2){
return 1;
}elseif($d1 == $d2){
return 0;
}else{
return -1;
}
}else{
/* if year is equal but month is less, therefore the first given date is less */
return -1;
}
}else{
/* if $y1 is less than $y2 */
return -1;
}
}
mcal_date_compare
(PHP 4)
mcal_date_compare — Compares two dates
Description
int mcal_date_compare
( int $a_year
, int $a_month
, int $a_day
, int $b_year
, int $b_month
, int $b_day
)
mcal_date_compare() Compares the two given dates, returns <0, 0, >0 if a<b, a==b, a>b respectively.
User Contributed Notes
mcal_date_compare
mcal_date_compare
nepnep_ at hotmail dot com
31-Oct-2007 03:46
31-Oct-2007 03:46
asharm4 at ilstu dot edu
14-Sep-2005 12:41
14-Sep-2005 12:41
//this function compares any date to current date and returns results in form of integers..
function date_compare ( $b_year, $b_month, $b_day )
{
$a_year = $today["year"];
$a_month = $today["mon"];
$a_day = $today["mday"];
$final_result = 9; //set it to random right now
if($a_year >$b_year)
{
$final_result = 1; //the year 1 is greater then year 2 so no more check required
}//year greater
else if($a_year == $b_year) //the years are the same ..so check the month
{
if($a_month > $b_month)
{
$final_result = 2; //the months are greater and so no more checks needed
}//greater month check
else
if($a_month == $b_month)//same months ..so check dates
{
if($a_day > $b_day)
{
$final_result = 3; //the days solve the problem :)
}
else if($a_day == $b_day)
{
$final_result = 4; //the dates are identical too..so date1 becomes equal to date 2
}
else
{
$final_result = -3; //the date1 < $date 2
}
}//equal month check
else
{
$final_result = -2;
}//month1 < month2
}//year same
else
{
$final_result = -1; //the year 1 is smaller then year 2 ..hence date1 < date2
}
return $final_result;
}
asharm4 at ilstu dot edu
14-Sep-2005 12:25
14-Sep-2005 12:25
//function to compare existing date from database to the current date
$check_array_deadline = explode("/", "08/24/2005");//this date is from database and in the format mm/dd/yyyy
$a_year = $today["year"];
$a_month = $today["mon"];
$a_day = $today["mday"];
$b_year = $check_array_deadline[2];
$b_month = $check_array_deadline[0];
$b_day = $check_array_deadline[1];
$check_date = date_compare( $a_year, $a_month, $a_day, $b_year, $b_month, $b_day );
function date_compare ( $a_year, $a_month, $a_day, $b_year, $b_month, $b_day )
{
$final_result = 9; //set it to random right now
if($a_year >$b_year)
{
$final_result = 1; //the year 1 is greater then year 2 so no more check required
}//year greater
else if($a_year == $b_year) //the years are the same ..so check the month
{
if($a_month > $b_month)
{
$final_result = 2; //the months are greater and so no more checks needed
}//greater month check
else
if($a_month == $b_month)//same months ..so check dates
{
if($a_day > $b_day)
{
$final_result = 3; //the days solve the problem :)
}
else if($a_day == $b_day)
{
$final_result = 4; //the dates are identical too..so date1 becomes equal to date 2
}
else
{
$final_result = -3; //the date1 < $date 2
}
}//equal month check
else
{
$final_result = -2;
}//month1 < month2
}//year same
else
{
$final_result = -1; //the year 1 is smaller then year 2 ..hence date1 < date2
}
return $final_result;
}

mcal_create_calendar