简体   繁体   中英

Get records exactly N days ago

I would like to select records that was created exactly N days ago.

I have something like this:

WHERE created_at = NOW() - (N || ' days')::interval

But this doesn't work, any ideas?

You should use the date part I believe, something like:

select created_at::date = (current_date - (N || ' days')::interval)::date;

This will take the date part of your timestamp:

select '2016-06-28 07:51:19.583104'::date

Will give you:

2016-06-28

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM