如何将当前日期与MySQL中的给定日期进行比较

时间:2014-03-14 08:17:40

标签: sql jsp

如何将当前日期与MySQL中的给定日期进行比较我正在使用该代码,但它无效。

  <%
    rs=st.executeQuery("select approcode,approemail,appromon,approvemon,approtue,approvetue,approwed,approvewed,approthr,approvethr,approfri,approvefri,approsat,approvesat,commen,months,SUM(nol) from `pushkalit`.`approval`WHERE (CONVERT( `approcode` USING utf8 ) LIKE '%"+user+"%') AND appromon=DATE(now()) OR approtue=DATE(now()) OR  approwed=DATE(now()) ");
     // i have given in mysql, appromon varchar(30).....so on dateformat have dd/MM/yyyy
    %>

3 个答案:

答案 0 :(得分:0)

您可以将其比作

DATE(NOW()) = DATE(duedate)

仅比较日期部分。

答案 1 :(得分:0)

你应该尝试使用简单的代码asL:

SELECT * FROM myTable WHERE DATE(myDate) = DATE(NOW())

答案 2 :(得分:0)

请参阅DATE_FORMAT()

SELECT 
    approcode, approemail, appromon, approvemon, approtue,approvetue, approwed, approvewed, approthr, approvethr, approfri, approvefri, approsat, approvesat, commen, months, SUM(nol) 
FROM `pushkalit`.`approval`
WHERE (CONVERT(`approcode` USING utf8) LIKE '%"+user+"%')
   AND ( appromon  = DATE_FORMAT(NOW(), "%d/%m/%Y") 
   OR    approtue  = DATE_FORMAT(NOW(), "%d/%m/%Y") 
   OR    approwed  = DATE_FORMAT(NOW(), "%d/%m/%Y") )

请注意,我在OR条件下插入了parens,因为我认为这实际上是您要查询的内容。