
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to make MySQL's NOW() and CURDATE() functions use UTC?
- How can I use the arithmetic operators (+,-,*,/) with unit values of INTERVAL keyword in MySQL?
- How MySQL behaves if I use INTERVAL keyword with an invalid date?
- How can I use MySQL INTERVAL keyword while extracting the part of the date?
- How MySQL behaves when we use INTERVAL of time unit with CURDATE() function?
- CURDATE () vs NOW() in MySQL
- What MySQL returns if I use enclosed set of unit values with INTERVAL keyword?
- How to use CONTAINS() with CURDATE in MySQL?
- How can I use MySQL INTERVAL() function with a column of a table?
- What is the difference between MySQL NOW() and CURDATE() function?
- Can we use INTERVAL keyword while inserting date records in a MySQL table?
- What are the different unit values that can be used with MySQL INTERVAL keyword?
- Can I write my own MySQL functions to use in MySQL queries?
- How can I use SPACE() function with MySQL WHERE clause?
- How to get the previous day with MySQL CURDATE()?

Advertisements