MySql query data by time period method example description

WBOY
Release: 2016-07-29 08:39:12
Original
1051 people have browsed it

The time format is 2008-06-16
Query the current day’s data:
SELECT * FROM `table` WHERE date(time field) = curdate();
Query the current month field:
SELECT *
FROM `table`
WHERE month( Time field) = month( now( ) );
The time format is 1219876... UNIX time, just apply the "FROM_UNIXTIME( )" function
For example, query the current month:
SELECT *
FROM `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) );
How about querying the previous month? Be flexible!
SELECT *
FROM `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) -1;
It’s that simple, more complicated details will be added later!

The above has introduced the MySql method of querying data by time period, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!