Skip to content

Instantly share code, notes, and snippets.

@mamantoha
Created November 17, 2016 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mamantoha/64c3fd7963701372df460416f3a902ff to your computer and use it in GitHub Desktop.
Save mamantoha/64c3fd7963701372df460416f3a902ff to your computer and use it in GitHub Desktop.
PostgreSQL: query to select records from last week on weekdays between 9:00 and 18:00
Model
.where(
"EXTRACT(dow FROM log_in) IN (1,2,3,4,5)"
)
.where(
"log_in::time BETWEEN '9:00' AND '18:00'"
)
.where(
"log_in BETWEEN now()::timestamp - (interval '1 week' AND now()::timestamp)"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment