Hey,
I am fairly new to PHP, but I have completed a few date comparison projects as of late.
I usually pick the dates apart into $current_month, $current_day, $current_year variables. I do the same with desired month, date year. Then I use if statements to compare the two and throw errors accordingly. See below:
<?PHP
//Lets breakdown the Current Date. If you are using a different date structure, modify the substr accordingly.
//If you need more help on substr, search PHP substr on google and click the first link.
$current_date = date("mdy");
//These three lines pull the year, date and month into seperate variables to work with.
$current_m = substr($current_date,0,2);
$current_d = substr($current_date,2,2);
$current_y = substr($current_date,4,2);
//Lets breakdown the Target Date I am replacing the / with nothing because it is less confusing and the numbers
//are the same as above.
$target_date = "12/20/07";
$target_date = trim(str_replace("/","",$target_date));
$target_m = substr($target_date,0,2);
$target_d = substr($target_date,2,2);
$target_y = substr($target_date,4,2);
//Now your months, days, and years are broken into seperate variables. This can be accomplished with arrays too
//but this is easier if your not familiar with arrays.
//Lets set some error messages to tell us why we are being rejected!
$error_y = "You have selected a year in the past.";
$error_m= "You have selected a month in the past.";
$error_d = "You have selected a day in the past.";
//Lets test to see if the target date is before the current date.
if($target_y > $current_y){
if($target_m > $current_m){
if($target_d > $current_d){
echo "SUCCESS! You have selected a date that is not today or before today but in the future!";
}else{
echo $error_d;
}
}else{
echo $error_m;
}
}else{
echo $error_y;
}
?>
Let me know if this helps.