0

I want to get only those records of my model which belong to a particular month. I am using:

Order.where(created_at.strftime("%B"): "April")

where created_at is DateTime. created_at.strftime("%B") gives me month, but it does not work. Any alternative?

sawa
  • 165,429
  • 45
  • 277
  • 381
Umesh Malhotra
  • 967
  • 1
  • 10
  • 25

1 Answers1

1

You'll probably have to do this in plan SQL (not the activerecord DSL):

Order.where("strftime('%m', created_at) = ?", 'April')

This uses the SQLite function to extract the month name

(I haven't done Rails in a while, let me know if this doesn't work)

Will Richardson
  • 7,780
  • 7
  • 42
  • 56