Re: checking dates not working

From: Date: Thu, 10 Nov 2011 22:48:30 +0000
Subject: Re: checking dates not working
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-315633@lists.php.net to get a copy of this message
On Thu, Nov 10, 2011 at 4:35 PM, Marc Fromm <Marc.Fromm@wwu.edu> 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"]); > } Why in the world are you comparing the formatted display dates instead of the numeric dates set by strtotime? if (!strtoftime($jobs_effective_start) >= strtotime(WSOFFBEGIN)) will do what you want. Also -- why not just set WSOFFBEGIN to the converted date value instead of converting it each time you use it? (Assuming that's a defined constant.) define('WSOFFBEGIN',strtotime("YYYY-MM-DD")); or whatever. If you need both forms (string and numeric) define two constants, one dependent on the other.

« previous php.general (#315633) next »