如何从我使用(日期)的数据库中减去今天的日期-30天

时间:2016-04-27 12:02:19

标签: php database

我需要帮助确定如何从数据库表中按日期计算-30天 然后计算从今天起约有30天的发票数量

2 个答案:

答案 0 :(得分:6)

从今天起减少30天内的PHP

echo date('Y-m-d', strtotime('-30 days'));

答案 1 :(得分:0)

在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();
相关问题