Last active
November 6, 2016 20:25
-
-
Save dominiceden/476f5ab3be5b7165b43532ff77f559c5 to your computer and use it in GitHub Desktop.
Get dates for a particular date range and a day of the week in PostgreSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monday is 1 | |
# Tuesday is 2 | |
# Wednesday is 3 | |
# Thursday is 4 | |
# Friday is 5 | |
# Saturday is 6 | |
# Sunday is 7 | |
# Note - the Postgres isodow function as used below gives us Monday - Sunday as 0-7. The dow function does Sunday-Monday, 0-6. | |
# Here we get all of Friday's appointments in a given date range and for a given barber_id. | |
Appointment.find_by_sql(SELECT * from appointments WHERE (barber_id = 1 AND EXTRACT(isodow FROM start_time) IN (5) AND start_time >= '2016-11-11 06:00:00' AND end_time <= '2016-11-18 10:00:00')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment