MySQL date compare problem? [closed]
SELECT * FROM shortleavedetails WHERE employee_code='17' AND
(DATE(authorizeddate) <= DATE(开发者_开发百科2011-1-1) AND DATE(authorizeddate) >= DATE(2010-5-1))
Put your date values in single quotes as they are literal strings, otherwise MySQL can't tell that's a date and not the number (2011 MINUS 1 MINUS 1 = 2009).
You don't need the DATE() casts around them either.
SELECT
*
FROM
shortleavedetails
WHERE
employee_code = '17'
AND
(DATE(authorizeddate) <= '2011-01-01'
AND
DATE(authorizeddate) >= '2010-05-01')
try this
SELECT * FROM shortleavedetails WHERE employee_code='17' AND
(authorizeddate<='2011-1-1' AND authorizeddate >= '2010-5-1')
SELECT * FROM shortleavedetails WHERE employee_code='17' AND authorizeddate between '2010-5-1'and '2011-1-1'
SELECT * FROM shortleavedetails WHERE employee_code='17' AND
authorizeddate <= '2011-01-01' AND authorizeddate >='2010-05-01'
精彩评论