How to round down a DateTime value

Posted by timpone on Stack Overflow See other posts from Stack Overflow or by timpone
Published on 2012-06-20T02:59:13Z Indexed on 2012/06/20 3:16 UTC
Read the original article Hit count: 245

I have a Location that can have Events. I want to have an upcoming_events method but want it to round down such that if someone looks at 10pm at night, it will show todays events. I have this:

def upcoming_events
  d=Time.new
  d.strftime("%m-%d-%Y")
  l=Event.where('location_id=? and start_datetime>?',self.id, d)
end

I gets converted down correctly but in d.strftime but the query is:

SELECT `events`.* FROM `events` WHERE (location_id=301 and start_datetime>'2012-06-20 02:49:23')

Any idea how to just get it to do '2012-06-20'?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby