开发者

MySQL date compare problem? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.
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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜