How to use the INTERVAL keyword with the MySQL NOW() and CURDATE() functions?

WBOY
Release: 2023-08-23 20:41:03
forward
630 people have browsed it

如何将 INTERVAL 关键字与 MySQL NOW() 和 CURDATE() 函数一起使用?

The INTERVAL keyword works similarly to the NOW() and CURDATE() MySQL functions in that it can be used with time, date, or datetime units of a date value.

Example

Using INTERVAL with MySQL NOW()

mysql> Select NOW() + INTERVAL 2 day; +------------------------+ | NOW() + INTERVAL 2 day | +------------------------+ | 2017-10-30 09:19:31 | +------------------------+ 1 row in set (0.00 sec) mysql> Select NOW() - INTERVAL 2 day; +------------------------+ | NOW() - INTERVAL 2 day | +------------------------+ | 2017-10-26 09:19:45 | +------------------------+ 1 row in set (0.00 sec) mysql> Select NOW() - INTERVAL 2 hour; +-------------------------+ | NOW() - INTERVAL 2 hour | +-------------------------+ | 2017-10-28 07:19:51 | +-------------------------+ 1 row in set (0.00 sec)
Copy after login

Example

Using INTERVAL with MySQL CURDATE()

mysql> Select CURDATE() - INTERVAL 2 day; +----------------------------+ | CURDATE() - INTERVAL 2 day | +----------------------------+ | 2017-10-26 | +----------------------------+ 1 row in set (0.00 sec) mysql> Select CURDATE() + INTERVAL 2 day; +----------------------------+ | CURDATE() + INTERVAL 2 day | +----------------------------+ | 2017-10-30 | +----------------------------+ 1 row in set (0.00 sec)
Copy after login

The above is the detailed content of How to use the INTERVAL keyword with the MySQL NOW() and CURDATE() functions?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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
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!