Ruff9
Ruff9

Reputation: 1202

Rails where date is monday

In Rails 6, how can I write a where query who find all records with a date attributes that is a monday ?

Something like : Appointment.where(date: monday?)

or Appointment.where('date.wday': 1)

Upvotes: 2

Views: 203

Answers (1)

Ruff9
Ruff9

Reputation: 1202

This is working with Postgres :

Appointment.where("extract(dow from date) = ?", Date.current.monday.wday)

Upvotes: 2

Related Questions