- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I use INTERVAL keyword with MySQL NOW() and CURDATE() functions?
INTERVAL keyword with NOW() and CURDATE() MySQL functions can be used in similar fashion as 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)
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)
Advertisements