1

I have an event listing site where i'm currently listing events occuring today by doing:

def load_today_events
 @today_events = Event.find(:all, :conditions => ['start_date =?', Date.today])
end

This works perfectly well.

I've recently introduced an end_date for events spanning more than one day.

Obviously, with the above code once the start_date has passed the event disappears from my listing.

I may be having a mental block here, but I can't for the life of me figure out how to show events that's start date has passed but end date has not.

I think I want something along the lines of:

find events where date.today is equal to or between start_date or end_date

Any ideas how best to approach this?

1 Answer 1

1

Not sure if i understand this correctly, but here are some examples of what you can do with dates.
In the example below, current_date is a postgresql function for the today date. This would match the events that the current_date is bigger or equal than start_date and less than end_date.

@today_events = Event.where("current_date >=  ? and current_date <= ?", start_date, end_date)

Another approach could be like this:

@today_events = Event.where("start_date >=  ? and end_date <= ?", start_date, end_date)

This example shows events that are from a current date interval.
This is the basics, so i hope you can apply to your own problem.

1
  • Thanks, that's been a great help.
    – Raoot
    Commented Sep 2, 2012 at 17:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.