php查询某年的数据 php查看一个变量的数据类型

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'),
【php查询某年的数据 php查看一个变量的数据类型】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按当前年份、季度、当月,查询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 获取今天之前,本周之前,本月之前,本年之前,今天,本周,本月,本年的数据呢/*今天*/
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');
/*查询上个月的数据*/
select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(date_sub(curdate(), interval 1 month),'%Y-%m');
其它获取类似以上的代码显示
关于php查询某年的数据和php查看一个变量的数据类型的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读