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

r937 rudy at r937.com
Tue Jul 7 21:47:43 CDT 2009


> 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 --

 '2009-05-30'
 '2009-5-30'
 '2009/05/30'
 '2009.5.30'
 '2009?05?30'


rudy
http://simply-sql.com/






More information about the thelist mailing list