3

Hey everyone. Here is my situation... I need to craft a sql query against a postgresql server that will return all records created within the past 5 minutes, rounded down to the lowest minute. So if cron kicks the query off at 12:05:25.000, it needs to query all records created since 12:00:00.000. So I guess I really have two issues.

  • I know using

    DATE_SUB(now(),INTERVAL 5 MINUTE)

    works in mysql - is there an equivalent in postgresql? I couldn't find any mention of it in the date/time functions documentation here.

  • Second, how do I tell it to round down to the minute (ignore seconds) for the 5 minute interval?

Any advice would be appreciated.

1 Answer 1

8
select current_timestamp - interval '5' minute

And to eliminate the seconds

select current_timestamp - interval '5' minute - 
  (extract(seconds from current_timestamp) || 'seconds')::interval
Sign up to request clarification or add additional context in comments.

1 Comment

or date_trunc('minute', t) to eliminate the seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.