Skip to content

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

@eteubert

Description

@eteubert

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions