Home  >  Article  >  Database  >  How to query records for a period of time in mysql

How to query records for a period of time in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-11-18 09:46:404156browse

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!

Statement:
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