views:

47

answers:

2

Hi I am trying to use a condition on events when the start_at DateTime is equal to or greater than Today's date. I want to list upcoming events, but clearly they are not upcoming if they have already passed.

I have:

@appointments = Event.find(:all, :conditions => ['move_id = ? AND start_at = ?', @move.id, Date.today])

I think I may be comparing apples and oranges here. It doesn't throw and error, just doesn't do what it is supposed to.

Help! Thanks in advance.

A: 

Try:

@appointments = Event.find(:all, :conditions => ['move_id = ? AND start_at >= ?', @move.id, DateTime.now])

Weird is that I can't find DateTime#now documentation.

I'm using Postgres for this test.

>> Event.last.created_at.class
=> Time
>> Event.find(:first, :conditions => ['created_at >= ?', DateTime.now]).valid?
=> true

Migration field code

t.datetime "created_at", :null => false
retro
Thanks, I did actually try that too and while it pulls the DateTime for now it doesn't seem to perform comparing the two?
looloobs
What's that start_at column type ?
retro
start_at column is a DateTime
looloobs
My answer updated.
retro
A: 

as you said, start_at is equal or greater than today's date, perhaps it was a problem with the operator that was checking your event's start_at with today's date

Evento.find(:all, :conditions => ['start_at >= ?', DateTime.now])

if you're using mysql you could use "start_at >= CURRENT_DATETIME" or something like this also

vrsmn