TP5查询当天,昨天,当月数据whereTime()

Db::whereTime('time','today')->select() //获取今天的数据

Db::whereTime('time','yesterday')->select() //获取昨天的数据

Db::whereTime('time','week')->select() //获取本周的数据

Db::whereTime('time','last week')->select() //获取上一周的数据

Db::whereTime('time','month')->select() //获取本月的数据

Db::whereTime('time','year')->select() //获取今年的数据

Db::whereTime('time','last year')->select() //获取去年的数据

 

//当天数据

$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));

$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;

$map['create_time'] = array('between', array($beginToday,$endToday));

 

//昨天数据

$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));

$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

$map['create_time'] = array('between', array($beginYesterday,$endYesterday));

 

//按日期和分类 分组查询

//create_time 字段在数据库里为时间戳

 

$list = M('user')->where($map)

->field("DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d') as date,count(*) as total,type")

->group("DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d'),type")

->select();

$list = array_reverse($list);

 

//ip地址过滤

$distinct_click_ip_list = M('user')

->where(array('type'=>1))

->field("DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d') as date,count(distinct create_ip) as distinct_total,type")

->group("DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d'),type")

->select();

posted @ 2021-06-29 15:01  blog_zss小帅-博客猿  阅读(3292)  评论(0编辑  收藏  举报