
- 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 MySQL INTERVAL keyword while extracting the part of the date?
With the help of following example we can understand that how we can use MySQL INTERVAL keyword with EXTRACT() function −
mysql> Select StudentName, RegDate, EXTRACT(YEAR from RegDate+INTERVAL 2 year) AS 'Two Year Interval' from testing where StudentName = 'Gaurav'; +-------------+---------------------+-------------------+ | StudentName | RegDate | Two Year Interval | +-------------+---------------------+-------------------+ | Gaurav | 2017-10-29 08:48:33 | 2019 | +-------------+---------------------+-------------------+ 1 row in set (0.02 sec)
Above query is showing how we can use INTERVAL keyword with EXTRACT() function used in MySQL table query.
mysql> Select EXTRACT(Year from '2017-10-22 05:03:45' + INTERVAL 2 Year) AS 'Two Year Interval'; +-------------------+ | Two Year Interval | +-------------------+ | 2019 | +-------------------+ 1 row in set (0.00 sec)
Above query is showing how we can use INTERVAL keyword with EXTRACT() function used for particular given date.
- Related Articles
- Can we use INTERVAL keyword while inserting date records in a MySQL table?
- How MySQL behaves if I use INTERVAL keyword with an invalid date?
- How can I use the arithmetic operators (+,-,*,/) with unit values of INTERVAL keyword in MySQL?
- How can I use INTERVAL keyword with MySQL NOW() and CURDATE() functions?
- What MySQL returns if I use enclosed set of unit values with INTERVAL keyword?
- How can we obtain the part of a date in MySQL?
- How can I use MySQL INTERVAL() function with a column of a table?
- While creating a MySQL table use the reserved keyword ‘Key’
- What is the use of MySQL BINARY keyword while performing string comparison?
- How can we use ORDER BY clause while calculating the Date?
- What are the different unit values that can be used with MySQL INTERVAL keyword?
- In MySQL, how can I insert date and time automatically while inserting NULL values to the other columns?
- How can I use TIME_FORMAT() function to offload time/date values in MySQL?
- How can I become part of the blockchain?
- How can I the date of creation and updation of tables in MySQL?

Advertisements