Skip to content

Instantly share code, notes, and snippets.

@slattery
Created July 2, 2012 02:20
Show Gist options
  • Save slattery/3030549 to your computer and use it in GitHub Desktop.
Save slattery/3030549 to your computer and use it in GitHub Desktop.
Find the next occurence of a day of the week in postgresql
-- I'd gladly pay you Tuesday for a hamburger today!
-- OK, see you next Tuesday.
SELECT *
FROM generate_series
(
current_date + '1 day'::interval, -- in case now() is same dow
current_date + '7 days'::interval,
'1 day'
) as s(a)
WHERE
(select EXTRACT(ISODOW FROM s.a)) = '2';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment