mysql's method of getting data by time period
- 2020-05-15 02:23:54
- OfStack
The time format is 2013-03-12
Query the data of the day:
Query out the current month field:
The time format is 1219876... UNIX time, simply apply the "FROM_UNIXTIME()" function
For example, query month:
What about the last month? Change 1!
Query the data of the day:
SELECT * FROM `table` WHERE date( The time field ) = curdate();
Query out the current month field:
SELECT *
FROM `table`
WHERE month( The time field ) = month( now( ) ) ;
The time format is 1219876... UNIX time, simply apply the "FROM_UNIXTIME()" function
For example, query month:
SELECT *
FROM `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) ;
What about the last month? Change 1!
SELECT *
FROM `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) -1;