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
Shared queries and folders ✅ Version history ✅ One-click connection to Redshift ✅
Get more done, together, with PopSQL and Redshift