views:

20

answers:

1

I for the life of me can't figure out the correct syntax to show the count of events before and after today.

Here's my awful and disgusting attempt:

Events.find(:all).select {|e| e.date > Time.now}.size

The trouble is the > or < operators don't work with Time.. :D

+1  A: 

I believe this works:

# events before today
@events = Events.all(:conditions => ["date < ?", Time.now.beginning_of_day])

# events after today
@events = Events.all(:conditions => ["date > ?", Time.now.end_of_day])

# events for today
@events = Events.all(:conditions => ["date BETWEEN ? AND ?",
   Time.now.beginning_of_day, Time.now.end_of_day])
j.
You're awesome! Strange such different syntax for time. Reminds me of SQL syntax.
Trip
Glad it helped :]
j.