Hi, I need to find the closest date to a given date using a rails named scope.
With MySql I could use DATEDIFF but I want to keep database agnosticism, following doesn't work with Sqlite:
named_scope :closest_to, lambda { |*args|
date = args.first
count = args[1] || 1
{:limit => count, :order => "ABS(DATEDIFF(hour, date_field, #{date.to_formatted_s :db}))"}
}