Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all records that were created on a specific day of the week

I need to find all records that were created on a specific day of week. I only have available to me the standard model datetime timestamps. How would I go about doing this in activerecord?

like image 679
KJF Avatar asked Sep 18 '25 20:09

KJF


1 Answers

To follow up on Justin's answer

where("extract(dow from created_at) = ?", Date.today.wday)

This is what I'm using in my application for postgres. This will find all records that were created on the same day-of-week as today. For example, if today was tuesday it would find all records created on tuesdays.

like image 108
Joey Hoang Avatar answered Sep 20 '25 09:09

Joey Hoang