I have the House model, with the painted_el attribute.
This field is defined in the table as a string in this format dd-mm-yyyy, a typical example would be this value "20-06-2021"), which would read as June 20, 2021.
The point is that I need to know which houses are already painted (lower than today) or are going to be painted (same or higher than today) based on this string field called painted_el.
I tried this, but it doesn't work: In the House model I created this method.
def pintada_el
Date.parse(self[:pintada_el]).strftime('%Y%m%d')
end
and in the helper I have this assignment that does not walk:
casas_por_pintar = Casa.where("pintada_el > TIMESTAMP 'now'").size
casas_pintadas = Casa.where("pintada_el <= TIMESTAMP 'now'").size
The problem is that you should do the date comparison at the database level, so that's where you should convert the text to a date. You didn't say which database engine you're using, but in PostgreSQL you could use something like: