A handy tip here from Karol Galanciak demonstrating how to use PostgreSQL’s EXTRACT function:
We can use
EXTRACT
andnow()
functions—the former could be used for extracting the current year from a timestamp and the latter could be used for getting the current time.Order.where("EXTRACT(year FROM created_at) = EXTRACT(year FROM now())")