Skip to content

EXTRACT

  • unit: This parameter indicates the part of the date or time to extract. Some of the valid unit values include YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, WEEK, QUARTER, DAYOFWEEK, DAYOFYEAR, etc.
  • date: This denotes the date or datetime expression from which to extract a part. It can be a column in a table, a string literal, or a result of a function that returns date or datetime. The value can be a DATE, DATETIME, TIME, YEAR, TIMESTAMP data type or a numeric or string type that represents a date or datetime.
SELECT EXTRACT(YEAR FROM '2022-03-01');
2022

The EXTRACT function in MySQL is used to return a specific component from a date/datetime expression.

In the given example, EXTRACT function is extracting the YEAR from the date ‘2022-03-01’. The output returns ‘2022’ which is the extracted year.