24小时内上线商品:
SELECT * FROM goods
WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= add_time;
今天上线商品:
select * from goods where to_days(add_time)=to_days(now());
======参考=========
mysql查询今天、昨天、7天、近30天、本月数据
今天
select * from 表名 where to_days(时间字段名)=to_days(now());
昨天
SELECT * FROM `表名` where TO_DAYS(NOW()) – TO_DAYS(时间字段名) = 1;
/*DATEDIFF(now() , FROM_UNIXTIME(`时间字段名`)) = 1; //时间字段 存储类型为时间戳*/
7天
SELECT * FROM `表名` where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名);
/*DATEDIFF(now() , FROM_UNIXTIME(`时间字段名`)) = 7; //时间字段 存储类型为时间戳*/
近30天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名);
本月
SELECT * FROM 表名 WHERE DATE_FORMAT(时间字段名, ‘%Y%m‘ = DATE_FORMAT(CURDATE(), ‘%Y%m‘;
时间: 2024-10-25 12:59:59