date filter

Dave Smith wrote:

anyone know any examples of good code for a date range filter i can add
to my app to return only selected articles within that range based on
their created at date.

Here is how I fetch something similar. It is just a simple find.
Substitute the created_at field and it should work. Is that what you
are looking for?

@res =
Reservation.find(:all,

                        :conditions => [ "enddate >= ? and

startdate <= ?",Date.today,Date.today+120],

                        :order => "space_id,startdate ASC")

Norm wrote:

Dave Smith wrote:

anyone know any examples of good code for a date range filter i can add
to my app to return only selected articles within that range based on
their created at date.
  
Here is how I fetch something similar. It is just a simple find.
Substitute the created_at field and it should work. Is that what you
are looking for?

@res = Reservation.find(:all,
                            :conditions => [ "enddate >= ? and startdate
<= ?",Date.today,Date.today+120],
                            :order => "space_id,startdate ASC")

ok thats great but how do I initiate that from the code. so for example
the page will load index and collect the articles normally. but how do i
then get it to collect the articles using the date filter code here!?
sorry for such a noob question

Dave Smith wrote:

Norm wrote:
Dave Smith wrote:
anyone know any examples of good code for a date range filter i can add
to my app to return only selected articles within that range based on
their created at date.

 Here is how I fetch something similar. It is just a simple find.
Substitute the created_at field and it should work. Is that what you
are looking for?
@res = Reservation.find(:all,
:conditions => [ "enddate >= ? and startdate
<= ?",Date.today,Date.today+120],
:order => "space_id,startdate ASC")
ok thats great but how do I initiate that from the code. so for example the page will load index and collect the articles normally. but how do i then get it to collect the articles using the date filter code here!? sorry for such a noob question

I am not sure
I understand what you are trying to do. Are you trying to collect a
set of information and then letting the user specify some conditions
(date range) so you would then display only those objects that meet
that condition? If that is what you are doing you could treat it as
two separate actions in the controller each of which will do the
appropriate find from which you then render using the same view. There
might be another way to do it but I would probably first do it that way
and worry about optimizing when that becomes important.

Sorry if I misunderstand your problem.

Norm