lsankar4033 lsankar4033 - 2 years ago 111
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download