在Ecto中按DateTime查询 [英] Querying by DateTime in Ecto

查看:63
本文介绍了在Ecto中按DateTime查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我尝试过的.

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

我也尝试过

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

两个都返回相同的消息

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

据我了解,我应该在查询中使用Ecto.DateTime.也许我缺少明显的东西?谢谢!

From what I understand I am supposed to be using Ecto.DateTime in my queries. Maybe I am missing something obvious? Thanks!

推荐答案

:datetime类型是本机类型,仅适用于元组.如果您在架构中将列类型设置为Ecto.DateTime,它将可以使用更高级别的类型,例如Ecto.DateTime结构.

The :datetime type is a native type and works only with tuples. If you set your column type to Ecto.DateTime in your schema, it will be able to work with higher level types like the Ecto.DateTime struct.

这篇关于在Ecto中按DateTime查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆