Home >Backend Development >PHP Tutorial >MySql query data by time period method example description
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.