Searching by date

Hi,
Could anybody please help me to search the record by date

I have one products table. In that table I have created_at.I want to
search the records by date.

I mean, if i select month as january and year as 2006 then i want to get
the list as per that month only.
Ex:
Created At Product Price
2006-09-18 Ruby 4.5
2006-09-18 Ruby 4.5
2006-08-18 Ruby 4.5
2006-08-04 shq 8.0

If i select September then I should be able to see

Created At Product Price
2006-09-18 Ruby 4.5
2006-09-18 Ruby 4.5

So how to do that code?? please help me regarding this…

Thanks in advance
Harish

For the ruby side you can locate the month using the month() method on
your date variable. For the SQL side look in the reference for
BETWEEN. It’s commonly associated with date range searching.

And/or, see if your db supplies a way to extract a month from a date,
then select on that.

For example, you could do something like the following in mySql.

def whatever(month)
@products = Product.find(:all, :conditions => [‘month(created_on) =
?’, month]
end

You get the idea.

On 9/18/06, Brittain [email protected] wrote:

I have one products table. In that table I have created_at.I want to


Posted via http://www.ruby-forum.com/.


The best way to implement code quickly is to implement less of it.
(http://www.xprogramming.com/Practices/PracNotNeed.html) – Ron
Jeffries

On 9/19/06, Naga harish Kanegolla [email protected]
wrote:

For example, you could do something like the following in mySql.

def whatever(month)
@products = Product.find(:all, :conditions => [‘month(created_on) =
?’, month]
end

Often that means you have a recursive infinite loop somewhere. I’d
have to see the exact code though.


A wise man once told me it is not wise to quote what a wise man once
told you. – Unknown

Hi,
I tries like this. Its giving error. “stack level too deep”. wat is
meant by this error?? could u please help?

Harish

Michael C. wrote:

And/or, see if your db supplies a way to extract a month from a date,
then select on that.

For example, you could do something like the following in mySql.

def whatever(month)
@products = Product.find(:all, :conditions => [‘month(created_on) =
?’, month]
end

You get the idea.

On 9/18/06, Brittain [email protected] wrote:

I have one products table. In that table I have created_at.I want to


Posted via http://www.ruby-forum.com/.


The best way to implement code quickly is to implement less of it.
(http://www.xprogramming.com/Practices/PracNotNeed.html) – Ron
Jeffries

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs