![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 we fetch month and day from a given date in MySQL?
It can be done inflowing two ways −
(A) With the help of EXRACT() function - EXTRACT() function can fetch any part from MySQL TIMESTAMP value. Following is the example of fetching month and day from a given date.
mysql> Select EXTRACT(Month from '2017-10-22') AS 'MONTH'; +-------+ | MONTH | +-------+ | 10 | +-------+ 1 row in set (0.00 sec) mysql> Select EXTRACT(day from '2017-10-22')AS 'DAY'; +------+ | DAY | +------+ | 22 | +------+ 1 row in set (0.00 sec)
(B) With the help of MONTH() or DAY() function - Rather than passing month and day as one of the arguments of EXTRACT() function, we can use MONTH() and DAY() function to fetch the value of MONTH and DAY from a given date as follows −
mysql> Select DAY('2017-10-22')AS 'DAY'; +------+ | DAY | +------+ | 22 | +------+ 1 row in set (0.00 sec) mysql> Select MONTH('2017-10-22')AS 'MONTH'; +-------+ | MONTH | +-------+ | 10 | +-------+ 1 row in set (0.00 sec)
Advertisements