I have a raw sql query which returns a datetime field and I want to return a json with those results.
If I put the return value I get a complain:
(Poison.EncodeError) unable to encode value: {{2017, 3, 21}, {0, 0, 0, 0}}
If I try to transform it to string using Timex
:
Timex.format!(Ecto.DateTime.from_erl(datetime_field), "%Y-%m-%d %H:%M:%S", :strftime)
I get:
** (FunctionClauseError) no function clause matching in Ecto.DateTime.from_erl/1
If I skip the from_erl
part:
Timex.format!(datetime_field, "%Y-%m-%d %H:%M:%S", :strftime)
I get:
** (Poison.EncodeError) unable to encode value: {:error, :invalid_date}