Beginner :conditions question

So I’m trying to grab birthdays for the current month. But I have to do
some magic inside a condition and this messes up AR. Here is what I am

@upcoming_birthdays = People.find(:all, :conditions =>
“birthdate.strftime(’%M’) =’%M’)”) %>

Of course find is passing this directly and DQL doesn’t know what to do
with it. What is the correct way to pass this condition? Thanks!


Firstly, numeric months are “%m” , so maybe changing “M” to “m” will be

But, :conditions have to be written pretty much in SQL, and I think you
to pass in whole SQL date strings as well. Try something like:

:conditions => [ “birthdate BETWEEN”%Y-%m-%01
%H:%M:%S") AND"%Y-%m-%31 %H:%M:%S")" ])

Actually, rails extends Date and Time in neat ways. You could write
something like instead of
about with strftime at all.

You can read up on all that in
ActiveSupport::CoreExtensions::Time::Calculations in the api docs.

Lemme know if that works for you.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs