- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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)
- 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? day 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?
- How to get a Date from year, month and day in Java?
- Fetch month, day, year, etc. from ISODate in MongoDB?
- Format MySQL date and convert to year-month-day
- MySQL query to fetch date with year and month?
- Want to fetch only the month part from a date in MySQL
- Compare only day and month with date field in MySQL?
- How can I subtract a day from a Python date?
- How can we fetch all the records from a particular MySQL table?