EXTRACT() in MySQL — How It Works

What the MySQL EXTRACT() function does, with an example.

Published October 20, 2026

EXTRACT(unit FROM date) pulls a part from a date or time, such as YEAR, MONTH, DAY, HOUR or QUARTER. It is the standard SQL way to read date parts.

How it works

Combined units like YEAR_MONTH are also supported.

Try it in MySQL

SELECT EXTRACT(YEAR FROM '2026-11-12')
2026
SELECT EXTRACT(QUARTER FROM '2026-11-12')
4
SELECT EXTRACT(YEAR_MONTH FROM '2026-11-12')
202611

Practical examples

Example 1

SELECT EXTRACT(YEAR FROM '2026-11-12');
-- 2026

Example 2

SELECT EXTRACT(QUARTER FROM '2026-11-12');
-- 4

Example 3

SELECT EXTRACT(YEAR_MONTH FROM '2026-11-12');
-- 202611

Use it in a real query

SELECT EXTRACT(YEAR FROM '2026-11-12');

Common mistakes

  • Using it in WHERE on indexed columns.
  • Wrong unit names.
  • Zero-padding expectations with YEAR_MONTH.

Key takeaways

  • EXTRACT() in one line: EXTRACT(unit FROM date) pulls a part from a date or time, such as YEAR, MONTH, DAY, HOUR or QUARTER.
  • Try queries in a test database first.
  • Check NULL handling and data types.

FAQ

EXTRACT vs YEAR()?

Equivalent; EXTRACT is portable across databases.

Does EXTRACT() work in other databases?

Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.

More SQL articles