There is a table with records. Records have a date_start field ( DATE type).
I want to get a record whose date is as close as possible to Time.zone.today .
The first thing that comes to mind is to initially sort them by date_start , and then:
.order(date_start: :desc).where('date_start <= ?', Time.zone.today).first But this method does not work exactly and sometimes gives incorrect results.