Select year from database as datetime

I got in database datetime field
I need to pick all data from database where date is this year
sample

database datetime a
2006-01-30 00:00:00 this date is this year 2006
2005-01-30 00:00:00 is not

sample

year = 2006
time_in -> looks now like that 2006-01-30 00:00:00

@hours = Hour.find(:all, :conditions => " time_in = " + year )

so I need do like : time_in.year = year
heh but it does not work of course

any one please …??

misiek wrote:

year = 2006
time_in -> looks now like that 2006-01-30 00:00:00

@hours = Hour.find(:all, :conditions => " time_in = " + year )

so I need do like : time_in.year = year
heh but it does not work of course

any one please …??

I assume this is an ActiveRecord / Rails issue. I cannot comment on the
details of that but from a DB background you need a range query.

select …
from …
where time_in >= ‘2006-01-01 00:00:00’ and time_in < ‘2007-01-01
00:00:00’

You can as well use “between”. HTH

Kind regards

robert