使用简单的日期字符串在datetime中创建一个插入的\u

使用简单的日期字符串在datetime中创建一个插入的\u,date,elixir,where,ecto,Date,Elixir,Where,Ecto,我试图在客户给我的某个日期之后插入记录 2018-06-06 下面是我编写查询的方式: {:ok, date} = NaiveDateTime.from_iso8601(date_string) from( m in query, where: m.inserted_at > ^date ) (MatchError)右侧值不匹配:{:错误,:无效的_格式} 当我尝试使用一个简单的日期对象时: **(exto.Query.CastError)lib/messages/sear

我试图在客户给我的某个日期之后插入记录

2018-06-06

下面是我编写查询的方式:

{:ok, date} = NaiveDateTime.from_iso8601(date_string)

from(
  m in query,
  where: m.inserted_at > ^date
)
  • (MatchError)右侧值不匹配:{:错误,:无效的_格式}
当我尝试使用一个简单的日期对象时:

**(exto.Query.CastError)lib/messages/search.ex:77:value
~D[2018-06-06]
中,其中
不能转换为查询中的type:naive_datetime


我如何才能找到在客户机传递给我的伪字符串日期之后插入的所有消息?

那里有ISO 8601日期,而不是日期时间。您可以将其转换为
datetime
(小时、分钟、秒均设置为0),如下所示:

iex(1)> date_string = "2018-06-06"
"2018-06-06"
iex(2)> ndt = NaiveDateTime.from_iso8601!(date_string <> " 00:00:00")
~N[2018-06-06 00:00:00]
iex(1)>日期 "2018-06-06" iex(2)>ndt=NaiveDateTime.from_iso8601!(日期字符串“00:00:00”) ~N[2018-06-06 00:00:00]
现在,您可以在查询中使用
ndt
,它将起作用。

您得到匹配错误,因为您没有从\u iso8601/1向
提供正确的数据。尝试附加一些虚拟时间信息并进行如下查询:
NaiveDateTime.from_iso8601(“2015-01-23 23:50:07”)