lsankar4033 lsankar4033 - 1 year ago 77
SQL Question

date_part with composite fields in PostgreSQL

Is it possible to use the

function to extract a composite of multiple specifiers?

For example, I'd like to extract the month, day of month, and hour of day from a timestamp in the single string form
so that

`SELECT date_part('day', TIMESTAMP '2001-02-16 20:38:40');`

would return


This is much easier with to_char():

select to_char(TIMESTAMP '2001-02-16 20:38:40', 'MM:DD:HH24')

The documentation describes the formatting options.