↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Functions / Date/Time Functions And Operators

Get timestamp subfield (equivalent to extract); see Section 9.9.1

Reading PG 18current·documented in 27 of 27 versions, 7.1 to 20

Signatures & examples

date_part ( text, timestamp ) → double precision
Get timestamp subfield (equivalent to extract); see Section 9.9.1
date_part('hour', timestamp '2001-02-16 20:38:40') → 20
date_part ( text, interval ) → double precision
Get interval subfield (equivalent to extract); see Section 9.9.1
date_part('month', interval '2 years 3 months') → 3
date_part('field', source)
Note that here the field parameter needs to be a string value, not a name. The valid field names for date_part are the same as for extract. For historical reasons, the date_part function returns values of type double precision. This can result in a loss of precision in certain uses. Using extract is recommended instead.
Version history 3
  1. 12 → 13 changed
  2. 7.4 → 8.0 changed
  3. 7.3 → 7.4 changed

Definition snapshot: b7bd9cda · English manual source