今天
SELECT * FROM `表名` where TO_DAYS(NOW()) – TO_DAYS(时间字段名) = 1;
SELECT * FROM `表名` where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名);
select * from 表名 where to_days(时间字段名)=to_days(now());
SELECT * FROM `表名` where TO_DAYS(NOW()) – TO_DAYS(时间字段名) = 1;
/*DATEDIFF(now() , FROM_UNIXTIME(`时间字段名`)) = 1; //时间字段 存储类型为时间戳*/
SELECT * FROM `表名` where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名);
/*DATEDIFF(now() , FROM_UNIXTIME(`时间字段名`)) = 7; //时间字段 存储类型为时间戳*/
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名);
SELECT * FROM 表名 WHERE DATE_FORMAT(时间字段名, '%Y%m' = DATE_FORMAT(CURDATE(), '%Y%m';
两个字段时间差
TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr2)
interval可是:
SECOND 秒 SECONDS
MINUTE 分钟 MINUTES
HOUR 时间 HOURS
DAY 天 DAYS
MONTH 月 MONTHS
YEAR 年 YEARS
selct TIMESTAMPDIFF(DAY,reg_time,pay_time)>=60