
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use MySQL INTERVAL Keyword to Extract Date Parts
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.
Advertisements