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?
In PostgreSQL 2 temporal data types namely timestamp and timestamptz where one is without timezone and the later is with timezone respectively, are supported to store Time and Date to a column. Both timestamp and timestamptz uses 8 bytes for storing timestamp values.
Introduction to PostgreSQL timestamp The timestamp datatype allows you to store both date and time. However, it does not have any time zone data. It means that when you change the timezone of your database server, the timestamp value stored in the database will not change automatically.
For timestamp with time zone , the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT ). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With