When using a date sigil, I can persist a structure, but when using Date.new, I get an error saying date is invalid

      sample_app_1 =
        IndieInfinity.DirectoryFixtures.app_fixture(%{
          name: "B Game",
          app_id: 1,
          app_type: "game",
          coming_soon: true,
          release_date: Date.new(2000, 1, 1)
        })

When I try and persist the structure above I get
** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{name: "B Game", app_id: 1, app_type: "game", coming_soon: true}, errors: [release_date: {"is invalid", [type: :date, validation: :cast]}], data: #IndieInfinity.Directory.App<>, valid?: false>}

When I do

      sample_app_1 =
        IndieInfinity.DirectoryFixtures.app_fixture(%{
          name: "B Game",
          app_id: 1,
          app_type: "game",
          coming_soon: true,
          release_date: ~D[2000-01-01]
        })

it works. The only difference is the use of the date sigil vs Date.new. How are the two different?

Date.new/ returns an {:ok, date} or {:error, reason} tuple. Perhaps you meant Date.new!/3 instead?

1 Like

Thank you! Yes, that was the issue.