Postgresql select timestamp with time zone, but ignore seconds

Ben Walker picture Ben Walker · Nov 3, 2015 · Viewed 7.8k times · Source

I'm selecting a timestamptz from a posgresql database. I want my select to return only the date, hours and minutes. No seconds. Can I set the date format in my psql select to accommodate this?

Answer

Erwin Brandstetter picture Erwin Brandstetter · Nov 3, 2015

You can use date_trunc() to truncate seconds and still return a timestamptz:

SELECT date_trunc('minute', ts_col) ...

Or you can use to_char() to return a formatted timestamp as text any way you like:

SELECT to_char(ts_col, 'YYYY-MM-DD HH24:MI') ...

Note that this will format the timestamptz according to your current time zone setting. Details: