[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

select year from database as datetime

misiek

1/31/2006 5:38:00 PM

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 ...??
1 Answer

Robert Klemme

2/1/2006 8:37:00 AM

0

misiek wrote:
> 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 ...??

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