DATE_PART()
SQL · Date Functions
Theory
DATE_PART is the function-style version of EXTRACT. Instead of the keyword form EXTRACT(MONTH FROM order_date), you write DATE_PART('month', order_date), passing the field name as a text string. Both return the same number, so DATE_PART('month', '2026-11-05') gives 11.
DATE_PART comes from PostgreSQL and is also available in Snowflake and Redshift. SQL Server has a similar function called DATEPART(month, order_date), with no underscore and no quotes around the unit. MySQL and SQLite do not have DATE_PART; MySQL uses EXTRACT or MONTH(), and SQLite uses strftime('%m', ...). A very common report pattern is to group by the extracted part, for example counting orders per month to see seasonality. Remember that a month number alone mixes years together, so group by year and month both when your data spans more than one year.
Why we use it
It does the same job as EXTRACT but in a normal function shape, which some people find easier to read and to build dynamically (the unit is just a string). It is the everyday choice in PostgreSQL-style code.
When to use it
Use DATE_PART in PostgreSQL, Snowflake or Redshift when you need a numeric part of a date. Use EXTRACT for code that should move between databases, and DATE_TRUNC when you want a real date (first day of the month) instead of a number.
How it works
- Call DATE_PART('month', order_date)
- Read the unit string ('year', 'month', 'dow'...)
- Decode order_date and pick that part
- Return a number such as 11
- Data spans several years? Yes: Group by year AND month together. No: Group by month alone.
- Counts or sums per period
Syntax
DATE_PART('field', date)Example
SELECT DATE_PART('month', hire_date) FROM employees;Key points
- Functionally identical to EXTRACT() in Postgres
- Field name is passed as a string, not a keyword
- Available in PostgreSQL, Snowflake and Redshift
- SQL Server's version is DATEPART(month, d) — no underscore, no quotes
- Group by year and month together when data covers more than one year