DateTime to utc_datetime?


I am struggling with dates and Ecto (3). My schema contains field(:matchdate, :utc_datetime).

In my app I build a datetime by

defp to_datetime(datetime_from_external_api) do
  {:ok, new_datetime, 0} = DateTime.from_iso8601("#{year}-#{month}-#{day}T#{hour}:#{min}:00Z")

This I use in creating the changeset:

        matchdate: to_datetime(to_string(api_matchdate))

This is the error message I get:

** (BadArityError) #Function<1.129354666/1 in MyProgram.fixtures/1> with arity 1 called with 2 arguments (#Ecto.Changeset<action: nil, changes: %{away_goals: β€œ3”, away_team_id: β€œ3348”, home_goals: β€œ0”, home_team_id: β€œ534”, match_id: β€œ63454”, match_round: β€œ1”, matchdate: ~U[2019-07-07 09:30:00Z], season: β€œ4”}, errors: [], data: #MyProgram.Match<>, valid?: true>, [])
(elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3

The error message doesn’t tell me anything. Do I have to convert my DateTime somehow to utc_datetime?

Thanks :slight_smile:

It looks very detailed for me :slight_smile:
The error is not in your datetime functions. You have declared an anonymous function in MyProgram.fixtures/1 function and it has arity 1 (expects 1 argument), but it was called with 2 arguments (changeset and empty list). You have a small hint at the end of the error message, Enum.reduce/3 expects a callback function with 2 arguments – element and accumulator, but you’ve implemented a function only with 1 argument.


Thanks. Oddly the function was in MyProgram.ex, not in fixtures.ex as mentioned in the error message.