Skip to content

Instantly share code, notes, and snippets.

@harssh
Forked from mamantoha/query.rb
Created February 15, 2023 14:35
Show Gist options
  • Save harssh/63139b6c94d676248d9de6f8003f1b2e to your computer and use it in GitHub Desktop.
Save harssh/63139b6c94d676248d9de6f8003f1b2e 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