Re: checking dates not working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 10, 2011 at 4:35 PM, Marc Fromm <Marc.Fromm@xxxxxxx> 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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux