- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 obtain the part of a date in MySQL?
By using EXTRACT() function we can obtain the part from current date or from given date. The parts of the date can be obtained in the form of year, month, days, hours, minutes, seconds and microseconds.
Examples
mysql> Select EXTRACT(Year from NOW()) AS YEAR; +-------+ | YEAR | +-------+ | 2017| +-------+ 1 row in set (0.00 sec)
Above MySQL query will obtain the year from current date.
mysql> Select EXTRACT(Month from '2017-09-21')AS MONTH; +-------+ | MONTH | +-------+ | 9 | +-------+ 1 row in set (0.00 sec)
Above MySQL query will obtain the month from given date.
- Related Articles
- How can I use MySQL INTERVAL keyword while extracting the part of the date?
- How can we calculate the Date in MySQL using functions?
- How can we offload the time/date handling in MySQL?
- How can we insert current date automatically in a column of MySQL table?
- How can we extract the Year and Month from a date in MySQL?
- How can we add day/s in the date stored in a column of MySQL table?
- How can we obtain different gases from the air?
- How can we fetch month and day from a given date in MySQL?
- How can we add a time interval to date stored in a column of MySQL table?
- In MySQL, how can we display the date in other format specified by the user?
- How to part DATE and TIME from DATETIME in MySQL?
- How can we get the structure of a MySQL view as we can get the structure of a MySQL table?
- How can we get the definition of a MySQL view as we can get the definition of a MySQL table?
- Want to fetch only the month part from a date in MySQL
- How can we search a record from MySQL table having a date as a value in it?

Advertisements