PostgreSQL Quick Tips: Working With Dates Using EXTRACT function

Saved on .

A handy tip here from Karol Galanciak demonstrating how to use PostgreSQL’s EXTRACT function:

We can use EXTRACT and now() 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())")

Visit “PostgreSQL Quick Tips: Working With Dates Using EXTRACT function”