mysql 时间查询

//查询最近6个月

SELECT * FROM Receipt WHERE ReceiptData between date_sub(now(),interval 6 month) and now() ORDER BY ReceiptData DESC;

//查询上一个月
SELECT * FROM Memo WHERE date_format(CreaterTime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m') ORDER BY CreaterTime DESC;

//查询本月
SELECT * FROM Memo  WHERE date_format(CreaterTime,'%Y-%m')=date_format(now(),'%Y-%m') ORDER BY CreaterTime DESC;

//查询当天
SELECT * FROM Memo  WHERE date(CreaterTime) = curdate() ORDER BY CreaterTime DESC;

//查询每周
SELECT	* FROM Memo GROUP BY WEEK(CreaterTime) 

//查询最近4周

SELECT CreaterTime FROM Memo WHERE YEARWEEK(date_format(CreaterTime,'%Y-%m-%d'))> YEARWEEK(DATE_SUB(NOW(),INTERVAL 4 WEEK)) GROUP BY YEARWEEK(CreaterTime);

//查询当天

SELECT * From Memo Where to_days(CreaterTime) = to_days(NOW())

//查询某天及以后的数据
SELECT * From Memo Where CreaterTime>=curdate()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值