Forum: Ruby select year from database as datetime

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9aa1e92a0ebb17fdaad2fa39b4c52b8a?d=identicon&s=25 misiek (Guest)
on 2006-02-01 23:55
(Received via mailing list)
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 ...??
5befe95e6648daec3dd5728cd36602d0?d=identicon&s=25 Robert Klemme (Guest)
on 2006-02-02 00:17
(Received via mailing list)
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
This topic is locked and can not be replied to.