How to compare a date in ruby? -
i running sql query returns orders each having date. want check orders made on current date ?
i able by:
orders = order.find_by_sql(query).reject {|o| today = time.now end_of_today = time.local(today.year, today.month, today.day, 23, 59, 59) start_of_today = time.local(today.year, today.month, today.day, 00,00,00 ) o.date > end_of_today o.date < start_of_today }.sort_by {|o| o.delivery_date }
'orders' contain orders made @ time today.
is there simpler way of doing in ruby ?
to orders made on current date, can following:
orders = order.where("date >= ?", time.zone.now.beginning_of_day).order(:delivery_date)
hope helps!
Comments
Post a Comment