mysql查询日期呈现昨天的记录而不是今天

时间:2010-11-29 16:14:05

标签: mysql

SELECT sum(AfterDiscount) AS
AfterDiscount,DATE_FORMAT(UpdateDate,'%d-%m-%Y')
as UpdateDate FROM tblsale where
date_format(UpdateDate,'Y-m-d')=date_format(now(),'Y-m-d')
AND BillType='s'

此查询今天呈现第28条记录,

我希望按今天的日期呈现记录

问题已解决,

SELECT sum(AfterDiscount) AS
AfterDiscount,DATE_FORMAT(UpdateDate,'%d-%m-%Y')
as UpdateDate FROM tblsale where
date_format(UpdateDate,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') AND BillType='s'

1 个答案:

答案 0 :(得分:4)

为什么不比较WHERE DATE(UpdateDate)=CURRENT_DATE()?为什么要格式化呢?

修改

此处的其他功能:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date