
- 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 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)
- Related Articles
- How can we extract the Year and Month from a date in MySQL?
- In MYSQL, how can we store a date where the day, month or both month & day are zero?\nday are zero?
- Fetch date records comparing with the current date’s day and month in MySQL
- Create date from day, month, year fields in MySQL?
- How can fetch records from specific month and year in a MySQL table?
- How to display first day and last day of the month from date records in MySQL?
- Want to fetch only the month part from a date in MySQL
- MySQL query to fetch date with year and month?
- How to get a Date from year, month and day in Java?
- Fetch month, day, year, etc. from ISODate in MongoDB?
- Compare only day and month with date field in MySQL?
- Format MySQL date and convert to year-month-day
- Finding day of week from date (day, month, year) in JavaScript
- How can we fetch all the records from a particular MySQL table?
- How to filter dates in MySQL to fetch date record only for a specific month?

Advertisements