Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: SELECT WHERE less than 15 minutes old

From the events table below, how do I select events created less than 15 minutes ago?

CREATE TABLE events (
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
like image 497
ma11hew28 Avatar asked Apr 13 '14 14:04

ma11hew28


2 Answers

SELECT created_at FROM events WHERE created_at > NOW() - INTERVAL '15 minutes';
like image 149
Frank Heikens Avatar answered Nov 02 '22 15:11

Frank Heikens


SELECT * FROM events WHERE age(now(), created_at) < '15 minutes';
like image 26
ma11hew28 Avatar answered Nov 02 '22 14:11

ma11hew28