Home > Backend Development > PHP Problem > How to query this year's data in php

How to query this year's data in php

藏色散人
Release: 2023-03-14 14:26:01
Original
2490 people have browsed it

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.

How to query this year's data in php

#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'))
);
Copy after login

The above is the query condition, which is directly applied to the query The statement is enough

$result = $db->where($where)->select();
Copy after login

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'))
);
Copy after login

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'))
);
Copy after login

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!

Related labels:
php
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