How does one go about storing datetime values from a date_select field in the database?
Here is my Ecto model:
defmodule MyApp.User do
use MyApp.Web, :model
schema "users" do
field :birthday, :utc_datetime
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:birthday])
end
end
You are right. Changing the column in the database to :date fixes the problem.
I find it weird though that it shouldn’t be possible to store a date value in a datetime field and just have the time-part assumed as midnight.
In this case it isn’t a big problem, but there might be cases where it is important to have the time-part in the database as well as the date in case you want to perform timezone-sensitive checks on the date…