Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Trying to query from a date range...everything from today [duplicate]

I'm trying to figure the best way to query a date range from rails...I looked around on Google but am unsure about how to use this syntax.

I have a Model that has various events and I like to add to my find condition a caveat that should only show events where the field :st_date is today or later, in effect only show me data that is current, nothing that happened before today.

I ran into a problem because I have no end date to stop the query, I want to query everything from today to next month.

I was thinking something like

 @events = Event.find(:all, :conditions => ["start_date between ? and ?",
         date.Today, date.next_month.beginning_of_month])

but I get the error undefined local variable or method `date'......

Do I need do anything particular to use the Date class? Or is there something wrong with my query syntax? I would really appreciate any help.

like image 977
ChrisWesAllen Avatar asked Apr 26 '10 21:04

ChrisWesAllen


1 Answers

Take a look at my by_star plugin which lets you do things like:

Event.by_month(Time.now, :field => "start_date")
like image 147
Ryan Bigg Avatar answered Oct 10 '22 21:10

Ryan Bigg