[thelist] simple question about comparing dates in PHP/MySQL

Nan Harbison nan at nanharbison.com
Wed Jul 8 05:31:01 CDT 2009

Thanks Rudy! I had come to this conclusion over time (by trial and error)
because it didn't seem to work, but I had no proof. I find the whole date
and time thing in databases a little confusing sometimes.
I am sure I will quote you on this!

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of r937
Sent: Tuesday, July 07, 2009 10:48 PM
To: thelist at lists.evolt.org
Subject: [thelist] simple question about comparing dates in PHP/MySQL

> This might be a stupid question, but someone was trying to tell me 
> that you can compare dates in the format: 2009-06-04 > 2009-05-30.

that is false

as written, those are arithmetic expressions, not dates

2009-06-04 evaluates to the integer 1999, while 2009-05-30 evaluates to the
integer 1974

clearly, not what was intended

written as date strings, however, yes, you can compare them meaningfully

  '2009-06-04' > '2009-05-30'

see the difference?

by the way, lee, mysql does not require date strings to zero-pad the month
or day

furthermore, mysql will recognize any character as the year/month/day
separator, so all of the following are valid dates --




* * Please support the community that supports you.  * *

For unsubscribe and other options, including the Tip Harvester and archives
of thelist go to: http://lists.evolt.org Workers of the Web, evolt ! 

More information about the thelist mailing list