bitwalker / timex_ecto

An adapter for using Timex DateTimes with Ecto
MIT License
162 stars 68 forks source link

How do I compare dates in queries with datetimetz? #76

Open eteubert opened 6 years ago

eteubert commented 6 years ago

With Ecto-Date fields I can do query comparisons like this:

from(e in query, where: fragment("? > NOW() - interval '24 hours'", e.some_date))

However that does not work.

operator does not exist: datetimetz > timestamp with time zone

I tried using Timex to generate the value to compare, but that did not work either:

from(e in query, where: e.some_date > ^one_day_ago())

defp one_day_ago do
  Timex.now()
  |> Timex.shift(hours: -24)
end