MySql query data method by time period (example)_PHP tutorial

WBOY
Release: 2016-07-21 15:49:03
Original
925 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’s 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, to 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 ones will be added later!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319603.htmlTechArticleThe time format is 2008-06-16. Query the data for the current day: SELECT * FROM `table` WHERE date(time field ) = curdate(); Query out the current month field: SELECT * FROM `table` WHERE month( Time field...
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!