我需要帮助来弄清楚如何按日期从数据库表中-30天然后计算从今天开始 -30 天的发票数量
从今天起在 php 中减少 30 天
echo date('Y-m-d', strtotime('-30 days'));
在SQL中使用interval
,例如:
create temporary table tmp (
d timestamp not null default current_timestamp on update current_timestamp
);
insert into tmp values
(now() - interval 1 day),
(now() - interval 32 day),
(now() - interval 33 day),
(now() - interval 10 day);
select * from tmp where d between now() - interval 30 day and now();