Hi all. Quick question about date comparisons:

I have the following code:

$err .= date("Y-n-j",strtotime($event_start_date)) < date("Y-n-j",time()) ? "<li class=\"err\">The start date you entered has already passed</li><br>": "";

This simply compares two dates, and writes an error if it returns true.

However, given that it's checking to see if 2002-8-10 is less than 2002-8-8 I cannot figure out why it's writing the error, when clearly 2002-8-8 arrives before 2002-8-10, and hence the above code should return false.

Now, the weird thing is that it happens no matter what day I select between now and Aug. 31, and as soon as I hit Sept. 1 it works fine.

Anyone have any ideas what could be causing this?

Thanks in advance,
P.

    Sorry, I included some html which made the code a little hard to interpret. It should be:

    $err .= date("Y-n-j",strtotime($event_start_date)) &lt; date("Y-n-j",time()) ? "&lt;li class=\"err\"&gt;The start date you entered has already passed&lt/li&gt;&lt;br&gt;": "";

    Thanks in advance,
    P.

      Because you're comparing strings - not dates. Why do you even need to call date function? Why not compare just strftime($event_start_time) and time() - they both will be numbers, not strings.

        Write a Reply...