Home > PHP Framework > ThinkPHP > How to query yesterday's data in ThinkPHP5

How to query yesterday's data in ThinkPHP5

藏色散人
Release: 2022-12-05 09:20:48
Original
1840 people have browsed it

How to query yesterday's data in ThinkPHP5: 1. Open ThinkPHP5 related files; 2. Use the expression "db('table')->whereTime('c_time', 'yesterday')->select( );" Just query yesterday's data.

How to query yesterday's data in ThinkPHP5

The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.

How to query yesterday’s data in ThinkPHP5?

ThinkPHP5 whereTime() usage method

Date interval query

Query today to the day after tomorrow based on timestamp

db('table')->whereTime('time', 'between', [strtotime(date('Y-m-d')), strtotime(date('Y-m-d', strtotime('+2 day')))])->select();
Copy after login

Query today to the day after tomorrow based on date

db('table')->whereTime('time', 'between', ['2020-3-28', '2020-3-30'])->select();
Copy after login

Expression query

Get today’s information

db('table')->whereTime('c_time', 'today')->select();
//也可以简化为下面方式
db('table')->whereTime('c_time', 'd')->select();
Copy after login

Get yesterday’s information

db('table')->whereTime('c_time', 'yesterday')->select();
Copy after login

Get this week’s information

db('table')->whereTime('c_time', 'week')->select();   
//也可以简化为下面方式
db('table')->whereTime('c_time', 'w')->select();
Copy after login

Get last week's information

db('table')->whereTime('c_time', 'last week')->select();
Copy after login

Get this month's information

db('table')->whereTime('c_time', 'month')->select();   
//也可以简化为下面方式
db('table')->whereTime('c_time', 'm')->select();
Copy after login

Get last month's information

db('table')->whereTime('c_time','last month')->select();
Copy after login

Get this year's information

db('table')->whereTime('c_time', 'year')->select();    
//也可以简化为下面方式
db('table')->whereTime('c_time', 'y')->select();
Copy after login
获取去年的信息
db('table')->whereTime('c_time','last year')->select();
Copy after login

Recommended learning: "thinkPHP Video Tutorial"

The above is the detailed content of How to query yesterday's data in ThinkPHP5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template