Mysql 日期

1、查询当前周记录

select * from table_name where week(createdTime) = week(now())

2、查询前7天记录

select * from table_name where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(createdTime)

3、查询当天记录

select * from table_name where to_days(createdTime) = to_days(now());
select * from table_time where date(createdTime) = curdate(); 

4、查询当月内记录

select * from table_name where MONTH(createdTime) = MONTH(now()) 

5、查询前一个月内记录

select * from table_name  where DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(createdTime);

 

posted @ 2017-07-31 17:29  vimx86  阅读(125)  评论(0编辑  收藏  举报