I know how to find records within a date range, and have seen answers to similar questions. My question is how to reformat my date value from "mm/dd/yy" to a format which can be compared to a date range, all within one query.
I have a column in my database that contains a date in "mm/dd/yy" format. I am trying to write a query that will select all records within a date range defined by start_date
and end_date
variables, which are Ruby Date
objects.
This is the best I have so far, but it's very slow:
date_records = Record.select { |r| ( (r.division == division) && (Date.strptime(r.date, "%m/%d/%y") >= start_date) && (Date.strptime(r.date, "%m/%d/%y") <= end_date) ) }