>
> It's not a good idea to store dates in the DB as strings.  You should
> store dates as dates in the DB.  SQL has date handling functions that
> you can use,

I agree with Marnen in this point. If you use a table "birthdays" for
storing the birthdays for users having fields
      user_id => :integer
      date => :date

then i think its better to use named_scope. As i said, if your model
name is Birthday then define a named_scope as
      named_scope :of_day, lambda { |date| {:conditions => { :day =>
date } } }

And call it like
      Birthday.of_day(Date.today)

That will generate a single query like following
      SELECT * FROM `birthdays ` WHERE (`birthdays `.`date` =
'2009-09-22')

This will give you a reusable and readable way you can apply for any
other days if you want.
Hope this will help :D

Thank you.

samiron
http://samironpaul.blogspot.com
http://www.scrumpad.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to