Compare timestamps

Hi everyone, 'Person' migration includes timestamps. I want to find every person created 'today'.

Tried the command below, but I think it compares hour,minute and seconds too. I just want to compare day,month and year. Person.find(:all, :conditions => {:created_at => Time.now})

any clues?

Hi everyone, 'Person' migration includes timestamps. I want to find every person created 'today'.

Tried the command below, but I think it compares hour,minute and seconds too. I just want to compare day,month and year. Person.find(:all, :conditions => {:created_at => Time.now})

You can't use the hash form of :conditions for this. You need to ask the database for those records with a created_at in a certain range (exactly what range will depend on your definiiton of today: past 24 hours or since midnight)

Fred

Person.all( :conditions => [ 'created_at BETWEEN ? AND ?', Time.now.at_beginning_of_day, Time.now.at_beginning_of_day + 1.day ] )

Thanks!

Okay, another issue: There are persons with the same names. I need to group them by their names and add their age(the ones that have same name).

this table:

Thanks everyone!