sqlsnowflake-cloud-data-platform

Need to truncate a timestamp and add a minute to it in SQL


I have a timestamp that goes into seconds. I want to truncate the time at the minutes (leaving off the seconds), and then i want to add a minute to that.

Example timestamps: 3001-01-01T07:59:00Z and 3001-01-01T07:59:59Z

My end goal is to have this time stamp be: 3001-01-01T08:00:00Z

I have the part to add the minute, but can't figure out the truncate part.

DATEADD(MINUTE,1, order.term_end::TIMESTAMP) AS "TermEnd"

Solution

  • Looks like you're looking for DATE_TRUNC.

    DATE_TRUNC('minute', order.term::TIMESTAMP)