Skip to main content

DATE_PART

Functions › Date and time

Returns one field of a date or timestamp as a number. DATE_PART('<field>', x) and EXTRACT(<field> FROM x) are the same function.

Syntax​

DATE_PART( '<field>', <date_or_timestamp> )

Arguments​

ArgumentDescription
'<field>'The field to return, in any case. See the table below.
<date_or_timestamp>A date or timestamp, or text that reads as one.
FieldValue
yearThe year, such as 2026.
quarter1 to 4.
month1 to 12.
weekThe ISO week number, 1 to 53.
dayThe day of the month, 1 to 31.
dowThe day of the week, 0 (Sunday) to 6 (Saturday).
isodowThe day of the week, 1 (Monday) to 7 (Sunday).
doyThe day of the year, 1 to 366.
hour0 to 23.
minute0 to 59.
secondThe seconds, with any fraction: 30.5.
epochSeconds since 1970-01-01 00:00:00 UTC, with any fraction.
decadeThe year divided by 10, rounded down: 202 for 2026.
century21 for 2026.

years, months, days, hours, minutes and seconds are accepted for the singular forms.

Returns​

An integer for every field except second and epoch, which return a float. When '<field>' is not a literal the result is a float. NULL when either argument is NULL.

Usage notes​

  • A date reads as midnight UTC. A timestamp without a time zone reads as UTC.
  • An unknown field fails the query. So does a value that does not read as a date or timestamp.
  • For date arithmetic, subtract epoch values and divide: 86400 seconds to a day. See EXTRACT.
  • Runs after the rows are read, except as in EXTRACT: an epoch comparison with a number is pushed as a filter.

Examples​

Revenue by year and quarter:

SELECT DATE_PART('year', o.placed_at) AS year,
DATE_PART('quarter', o.placed_at) AS quarter,
SUM(o.total) AS revenue
FROM Order o
GROUP BY DATE_PART('year', o.placed_at), DATE_PART('quarter', o.placed_at)
ORDER BY year, quarter
yearquarterrevenue
2026248210
2026352944.5

Orders placed at weekends:

SELECT o.key, o.placed_at
FROM Order o
WHERE DATE_PART('isodow', o.placed_at) >= 6

See also​

EXTRACT · DATE_TRUNC · CURRENT_DATE