开发者

mysql query date render yesterday records instead today

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'

This query render the 28 th records instead today ,

i want to render records by today dates

Problem fixed,

SELECT sum(AfterDiscount) 开发者_如何学CAS
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'


Why not compare WHERE DATE(UpdateDate)=CURRENT_DATE() ? Why go the trouble of formatting?

EDIT

Further functions found here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜