13

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?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Ben Walker
  • 2,037
  • 5
  • 34
  • 56

1 Answers1

25

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:

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228