php获取最近一周的数据 php获取昨天的日期

PHP mysql 查询 今天,昨天,最近7天的数据?今天
select * from 表名 where mytime(时间字段名) = mytime(now());
昨天
select * from 表名 where mytime( now( ) ) - mytime( 时间字段名) = 1
7天
select * from表名 where date_sub(cur(), interval(7 day = date(时间字段名)
如何用PHP 获取今天之前,本周之前,本月之前,本年之前,今天,本周,本月,本年的数据呢/*今天*/
select * from 表名 where to_days(时间字段) = to_days(now());
/*昨天*/
select * from 表名 where to_days(now())-to_days(时间字段) = 1;
/*近7天*/
select * from 表名 where date_sub(curdate(), interval 7 day) = date(时间字段);
/*查询距离当前现在6个月的数据*/
select * from 表名 where 时间字段 between date_sub(now(),interval 6 month) and now();
/*查询当前这周的数据*/
select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now());
/*查询上周的数据*/
select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now())-1;
/*查询当前月份的数据*/
select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(now(),'%Y-%m');
/*查询上个月的数据*/
select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(date_sub(curdate(), interval 1 month),'%Y-%m');
其它获取类似以上的代码显示
php如何获取数据库里上一周的数据?echodate('Y-m-d',strtotime ( "last Monday -1 week" )),"\n" ;
echodate('Y-m-d',strtotime ( "last Sunday" )),"\n" ;
通过这个函数获取上个周的开始和结束,然后sql查询
可以研究下这个函数strtotime。可以满足你的需求
【php获取最近一周的数据 php获取昨天的日期】关于php获取最近一周的数据和php获取昨天的日期的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读