How to use Elixir function in ecto query

I’m certainly not an Ecto expert, but I’m pretty sure that you can’t define custom functions in Elixir and use them inside Ecto queries (feel free to correct me if I’m wrong though).

What I would do for now is get your results and use a filter function to do what you want. Something like this

query = ...
Enum.filter(query, fn p -> date_difference(p.payment_schedule) == 2 end)

That way, you will get all of the results initially from the Ecto query, and then you will use Elixir to filter those based on your custom Elixir function. This might not be the best way to do it but I am fairly sure it would work.