php查询前一个月的数据 php查询前一个月的数据怎么查

phpcms 中怎么实现最近一个月的数据查询还有某个时间端的数据查询??用户模块在 phpcms/modules/member/member.php92行左右php查询前一个月的数据!
代码贴下:
//默认选取一个月内的用户php查询前一个月的数据,防止用户量过大给数据造成灾难
$where_start_time = strtotime($start_time) ? strtotime($start_time) : 0;
$where_end_time = strtotime($end_time) + 86400;
//开始时间大于结束时间 , 置换变量
if($where_start_time$where_end_time) {
$tmp = $where_start_time;
$where_start_time = $where_end_time;
$where_end_time = $tmp;
$tmptime = $start_time;
$start_time = $end_time;
$end_time = $tmptime;
unset($tmp, $tmptime);
}
PHP或mysql如何提取前一月某日到后一月某日的记录?数据库的表里面专门加一列记录时间的,这样用SELECT查询的时候可以对时间进行限制了,根据你的情况就是
$time1 = mktime(2010.5.8);
$time2 = mktime(2010.4.8);
$query = "SELECT *** FROM *** WHERE timetime1 AND time = time2";
至于mktime的参数怎么填,自己去查查手册吧 。
还有,记得插入记录的时候,要把time列的值设成当前时间值 , 也就是$now=time();
php怎么做1号至15号查询上个月的资料这个查询的sql语句是这样的select * from table(你查询资料的数据表名) where addtime(你资料表中添加时间的字段)=(1号的时间戳) and addtime=(15号的时间戳),这样你看下你要求出几个变量了:1号的时间戳和15号的时间戳,这样就可以查询出 1号至15号的资料了
php 如何获取一个月前的时间戳strtotime 非常强大的一个获取时间戳的函数
例:获取前一个月的时间
strtotime("-1 month");
获取上一个月的今天的上一天
date("Y-m-d",strtotime("-1 month - day"));
获取上近五年
strtotime("-5 year");
百度一下,这个网上有很多
如何用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个月php查询前一个月的数据的数据*/
select * from 表名 where 时间字段 between date_sub(now(),interval 6 month) and now();
/*查询当前这周php查询前一个月的数据的数据*/
select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now());
/*查询上周php查询前一个月的数据的数据*/
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显示一个月的记录从你的结构可以看出,你的日期使用的是UNIX时间戳,不是数据库的日期类型,这个可以使用函数FROM_UNIXTIME转换为数据库日期类型 , 然后使用date_format函数转换为指定格式 。也可以使用UNIX_TIMESTAMP函数把日期转换为时间戳进行比较 。
例如:查询本月的数据条件可以这样写:
WHERE date_format(FROM_UNIXTIME(`time`),'%Y%m')='201504'
还可以这样:
WHERE `TIME` BETWEEN UNIX_TIMESTAMP('2015-04-01 00:00:00') AND UNIX_TIMESTAMP('2015-04-30 23:59:59')
如果数据量特别多 , 后一种方式的查询速度更快,前提的`time`字段有索引 。

推荐阅读