Querying by DateTime

286 views
Skip to first unread message

Jonathan Birkholz

unread,
May 14, 2015, 3:32:40 PM5/14/15
to elixi...@googlegroups.com
Hey guys! New to Ecto. I am using it with the Phoenix framework.

I am having an issue with querying with DateTimes. I thought I was doing it right but clearly I am missing something crucial (and maybe obvious?)

I tried this:

date = Ecto.DateTime.from_erl(:calendar.universal_time())
  query |> where([record], record.deadline >= ^date)

And I tried this:

date = Ecto.DateTime.from_erl(:calendar.universal_time())
query = from m in MyApp.SomeModel,
      where: m.deadline >= ^date,
      select: m

Both end up with the same error:

value `%Ecto.DateTime{...}` in `where` cannot be cast to type :datetime in query

I have googled for a good amount of time without much luck.

I also posted a SO question. Any help would be greatly appreciated.

https://stackoverflow.com/questions/30245703/querying-by-datetime-in-ecto

Jonathan Birkholz

unread,
May 14, 2015, 3:52:39 PM5/14/15
to elixi...@googlegroups.com
Jose Valim provided the answer.

Just changed my field type from :datetime to Ecto.DateTime
Reply all
Reply to author
Forward
0 new messages