
正文
php获取当天的数据 php获取参数值的三种方式
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
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(时间字段名)
相关问答
Q1: php中用time()函数存入时间,如何查询当月的数据
这个time()函数是将时间保存成时间戳格式,则要查当月数据,只要查当月第一天到当月最后一天的之间的数据即可。
假设这个用来判断的字段是date
sql语句
SELECT ………… WHERE………… `date` = 本月第一天的time值 AND `date` 下个月第一天的time值
所以这里就只要获取当月第一天以及下个月第一天的时间戳
具体如下:
?php
$cur = date('Y-m',time());//当天年月
$cur_y = date('Y',time());//当天年份
$cur_m = date('m',time());//当天月份
$cur_f = $cur . '-1';//本月首日
$first = strtotime($cur_f);//时间戳最小值,本月第一天时间戳
//下月首日
if($cur_m=12){
$cur_n = ($cur_y+1) . '-1-1';
}else{
$cur_n = $cur_y . '-' . ($cur_m+1) . '-1';
}
$last = strtotime($cur_n);//时间戳最大值,下个月第一天时间戳
?
再把$first 和 $last 放入sql语句里面就可以查询到数据了
Q2: php怎么获取今天零点的时间戳
获取当天零点的时间戳, 可以按以下方法获得:
?php
//获取当天的年份
$y = date("Y");
//获取当天的月份
$m = date("m");
//获取当天的号数
$d = date("d");
//将今天开始的年月日时分秒,转换成unix时间戳(开始示例:2015-10-12 00:00:00)
$todayTime= mktime(0,0,0,$m,$d,$y);
//$todayTime即是当天零点的时间戳
?
Q3: 如何用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');
其它获取类似以上的代码显示
Q4: thinkPHP3.2.3怎么获取 总数 今天 昨天 本周 本月 数据量 代码不对 望大神整改
对前台传来的商品id数组在表中进行查询
//$goods = array(11,10,7);
$where['goods_id']=array("in",$goods);
$where['user_id'] = $_SESSION['uid'];
$res = D("cart")-where($where)-select();
复制代码
得到sql语句如下
"SELECT * FROM `cart` WHERE `goods_id` IN (11,10,7) AND `user_id` = 1
关于php获取当天的数据和php获取参数值的三种方式的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







