
正文
php获取一周前的数据 php获取前一天时间戳
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php如何获取数据库里上一周的数据?
echo date('Y-m-d',strtotime ( "last Monday -1 week" )), "\n" ;
echo date('Y-m-d',strtotime ( "last Sunday" )), "\n" ;
通过这个函数获取上个周的开始和结束,然后sql查询
可以研究下这个函数strtotime 。可以满足你的需求
相关问答
Q1: 如何用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');
其它获取类似以上的代码显示
Q2: 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获取一周前的数据的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php获取前一天时间戳、php获取一周前的数据的信息别忘了在本站进行查找喔。






