How to Round Timestamps in Redshift

Rounding/truncating timestamps are especially useful when you're grouping by time. The Redshift function you need here is TO_CHAR():

select to_char(sysdate, 'YYYY-MM-DD HH24:MI');

Truncating to date or year is easier because you can just use the TRUNC() and EXTRACT() functions, respectively:

select trunc(sysdate);
select extract(year from sysdate);
database icon
From Redshift query to chart to Slack in seconds
Get to answers faster, together, with PopSQL and Redshift