On 11/11/2011, at 11:35 AM, Marc Fromm wrote: > I have this bit of code to see if a date is greater or equal to a set date. > > echo(date("m/d/Y",strtotime($jobs_effective_start)));// displays entered date of 01/03/2012 > echo(date("m/d/Y",strtotime(WSOFFBEGIN))); // displays set date of 09/16/2011 > > if (!(date("m/d/Y",strtotime($jobs_effective_start)) >= date("m/d/Y",strtotime(WSOFFBEGIN)))) { > $error.="The effective start date must be AFTER ".WSOFFBEGIN."\n"; unset($_POST["jobs_effective_start"]); > } > > My error message is displaying. The if statement is executing as true, as if 01/03/2012 is not greater or equal to 09/16/2011. > This is not correct since a date in 2012 should be greater than a date in 2011. > > If I use 12/31/2011 as the $job_effective_start date the error message is not displayed since 12/31/2011 is greater than 09/16/2011 and the if statement executes as fasle. > > Any ideas on why a 2012 date is treated as not greater than a 2011 date? > > Thanks > > Marc String comparisons (which is what is happening here) are done left to right. so it's comparing month, then day, then year. You could use a Ymd format or just compare the values of strtotime(). --- Simon Welsh Admin of http://simon.geek.nz/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php