where($where)->select();"."/> where($where)->select();".">
Home > Article > Backend Development > How to query this year's data in php
How to query this year's data in php: 1. Get the time of this year through date; 2. Run the query statement "$result = $db->where($where)->select(); "That's it.
#The operating environment of this article: Windows 7 system, thinkphp v5.1 version, Dell G3 computer.
How to query this year's data in php?
thinkphp queries the data of the day, this week, this month, and this year
The code is such as:
//当天时间 $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')) );
The above is the query condition, which is directly applied to the query The statement is enough
$result = $db->where($where)->select();
Correction of the query time of this year above
$where['time'] = array( array('egt',strtotime(date('Y-01-01',time())), array('lt',strtotime(date('Y-01-01',time()).'+1 year')) );
Repaired version
//昨天时间 $yesterday['addtime'] = array( array('egt',strtotime(date('Y-m-d',time()).' -1 day')), array('lt',strtotime(date('Y-m-d',time()))) ); //当天时间 $day['addtime'] = array( array('egt',strtotime(date('Y-m-d',time()))), array('lt',strtotime(date('Y-m-d',time()).' +1 day')) ); // 本月时间 $month['addtime'] = array( array('egt',strtotime(date('Y-m',time()))), array('lt',strtotime(date('Y-m',time()).' +1 month')) ); // 本周时间 $week['addtime'] = 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')) );
Recommended learning: "PHP Video tutorial》《The latest 10 thinkphp video tutorials》
The above is the detailed content of How to query this year's data in php. For more information, please follow other related articles on the PHP Chinese website!