Home >Database >Mysql Tutorial >How to query records for a period of time in mysql
Mysql method of querying records for a period of time: 1. Query records within N days, the code is [WHERE TO_DAYS(NOW()) - TO_DAYS (time field) 9932edb438243ff36730e92f37f423e9 SELECT PERIOD_DIFF(9802,199703);
-> 11
DATE_ADD(date,INTERVAL expr type )
DATE_SUB(date,INTERVAL expr type)
ADDDATE(date,INTERVAL expr type)
SUBDATE(date,INTERVAL expr type)
These functions perform arithmetic operations on dates. ADDDATE() and SUBDATE() are synonyms for DATE_ADD() and DATE_SUB() respectively. In MySQL 3.23, if the right side of the expression is a date value or a datetime field, you can use and - instead of DATE_ADD() and DATE_SUB() (example below). The date parameter is a DATETIME or DATE value specifying the beginning of a date. expr is an expression that specifies whether to add or subtract the interval value from the start date. expr is a string; it can be preceded by a "-" to represent a negative interval value. type is a keyword that indicates the format in which the expression is interpreted.
The above is the detailed content of How to query records for a period of time in mysql. For more information, please follow other related articles on the PHP Chinese website!