Syntax
The syntax for the MySQL EXTRACT function is:
Parameters or Arguments
- date
The date or datetime value from which the date part is to be extracted.
- unit
The unit type of the interval such as DAY, MONTH, MINUTE, HOUR, and so on. It can be one of the following:
unit |
Compatibility |
MICROSECOND |
4.1.1+ |
SECOND |
3.2.3+ |
MINUTE |
3.2.3+ |
HOUR |
3.2.3+ |
DAY |
3.2.3+ |
WEEK |
5+ |
MONTH |
3.2.3+ |
QUARTER |
5+ |
YEAR |
3.2.3+ |
SECOND_MICROSECOND |
4.1.1+ |
MINUTE_MICROSECOND |
4.1.1+ |
MINUTE_SECOND |
4.1.1+ |
HOUR_MICROSECOND |
4.1.1+ |
HOUR_SECOND |
4.1.1+ |
HOUR_MINUTE |
3.2.3+ |
DAY_MICROSECOND |
4.1.1+ |
DAY_SECOND |
3.2.3+ |
DAY_MINUTE |
3.2.3+ |
DAY_HOUR |
3.2.3+ |
YEAR_MONTH |
3.2.3+ |
Example
Let's look at some MySQL EXTRACT function examples and explore how to use the EXTRACT function in MySQL.
For example: