a_b
a_b

Reputation: 1918

How do you query by a time delta with Ecto?

Trying to compose a query (finding all users created more than 30 days ago) that corresponds to the following psql query:

SELECT * FROM users
WHERE date_part('day', now()-inserted_at) > 30;

Upvotes: 1

Views: 126

Answers (1)

michalmuskala
michalmuskala

Reputation: 11278

from u in User, where: u.inserted_at > ago(30, "days")

https://hexdocs.pm/ecto/Ecto.Query.API.html#ago/2

Upvotes: 6

Related Questions