
正文
php获取年和周数据 php获取指定日期是星期几
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php如何获取数据库里上一周的数据?
php获取年和周数据你php获取年和周数据的数据库里需要有一个记录时间的字段,例如这个字段是posttime,每次插入数据的时候,都记录下当前的时间戳,也就是time()php获取年和周数据;
php获取年和周数据你需要得到上周开始,和上周结束的时间戳
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
3.查询的时候,WHERE 条件里加上 posttime=$beginLastweek AND posttime=$endLastweek
希望对你有帮助
相关问答
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如何获取本周和本月的数据进行排行
计算本周的,需要对今天进行判断,先计算出是星期几,然后计算出星期一是 几月几号,在算出星期天是几月几号, 然后在写到sql中,比如 2009-03-09到2009-03-15的话,sql就是
SELECT count( ID ) AS c FROM dede_archives WHERE UNIX_TIMESTAMP( '2009-03-15') pubdate UNIX_TIMESTAMP('2009-03-09') 下面还有一例。本月统计(MySQL)
select * from booking where month(booking_time) = month(curdate()) and year(booking_time) = year(curdate())本周统计(MySQL)
select * from spf_booking where month(booking_time) = month(curdate()) and week(booking_time) = week(curdate())
Q3: PHP 计算某日是这一年的第几周
在判断某一天是哪一年php获取年和周数据的第几周php获取年和周数据的时候php获取年和周数据,根据采用的国际标准(忘php获取年和周数据了叫什么名字了)php获取年和周数据,年首或者年末的那几天有可能不属于今年的第一周或者最后一周。
代码如下:
?php
echo date("oW",strtotime("20141229"))."\n";
echo date("oW",strtotime('20160101'))."\n";
?
扩展资料
php计算时间段的天数:
$firstday = date("Y-m-d H:i:s",time());//当前日期
$timestamp=strtotime($firstday);//当前日期时间戳
$firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)-1).'-01'));//上个月开始的日期
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));//上个月结束的日期
$stimestamp = strtotime($firstday);
$etimestamp = strtotime($lastday);// 计算日期段内有多少天
$days = ($etimestamp-$stimestamp)/86400+1;// 保存每天日期
$date = array();
for($i=0; $i$days; $i++){
$date[] = date('Y-m-d', $stimestamp+(86400*$i));
}
php获取年和周数据的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php获取指定日期是星期几、php获取年和周数据的信息别忘了在本站进行查找喔。






