php查询一年内的数据 php 查询

php读取mysql某段时间内所有数据(按月读取)比如查2012年11月到12月
select *
from test_table
where to_char(test_date,'yyyy-mm') = '2012-12'
这样
/********/
哦,那你可以这么做 。先在网页上加两个下拉列表选择框,第一个用来获取起始日期,第二个用来获得结束日期 。sql改为 SELECT
TO_CHAR(test_date, 'yyyy-mm') FROM
test_table WHERE
TO_CHAR(test_date, 'yyyy-mm') BETWEEN '2012-11' and '2012-12'
thinkphp中如何查询当天 , 本周的,本月的 , 本年的数据 , //当天时间
$where['time'] = array(
array('egt',strtotime(date('Y-m-d',time())),
array('lt',strtotime(date('Y-m-d',time())).'+1 day')
);
// 本周时间
$where['time'] = array(
array('egt',strtotime(date('Y-m-d',time())).'-'.date('w',time()).' day'),
array('lt',strtotime(date('Y-m-d',time())).'+1 week -'.date('w',time()).' day');
);
// 本月时间
$where['time'] = array(
array('egt',strtotime(date('Y-m',time()))),
array('lt',strtotime(date('Y-m',time()).'+1 month'))
);
// 本年时间
$where['time'] = array(
array('egt',strtotime(date('Y',time()))),
array('lt',strtotime(date('Y',time()).'+1 year'))
);
上面是查询条件,直接运用到查询语句就可以了
$result = $db-where($where)-select();
更正下上面的那个 本年 查询时间
$where['time'] = array(
array('egt',strtotime(date('Y-01-01',time())),
array('lt',strtotime(date('Y-01-01',time()).'+1 year'))
);
PHP中如何查询最近一天的所有数据?设php查询一年内的数据你的存储字段名为 your_column
其实很简单php查询一年内的数据,如果你的存放时间的字段是datetime
直接
where your_column'".date('Y-m-d',time())." 00:00:00';就好了
如果使用的unix时间戳,用整数存储的
就这样
$day_begin=strtotime(date('Y-m-d',time()));
然后
where your_column".$day_begin."就好了
php按当前年份、季度、当月,查询mysql数据库并输出数组PHP查询到的数据存放到数组里面,一般使用$arr[]=$row的方式实现,$row是mysql_fetch_array获得的一行数据 , 本身是一个数组,执行上面的语句之后,这一行会添加存放在额为数组$arr的最后 。典型的例子代码是这样的:mysql_connect('127.0.0.1', 'root', '123456');$sql='select * from test.tab';if ($res=mysql_query($sql)){while($row=mysql_fetch_array($res)) $result[]=$row;mysql_free_resule($res);}else echo "执行SQL语句:$sql\n错误:".mysql_error();echo '查询结果在下面的额为数组里面:';print_r($result);echo '';
我刚学PHP的,现在想做一个统计,统计一年的开始到现在时间内的数据,时间段的代码不会写,急...sql 语句查询 between and
如 select * from tableName where data between xxx and xxx;
如何用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());
/*查询上周的数据*/
select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now())-1;
/*查询当前月份的数据*/
select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(now(),'%Y-%m');

推荐阅读