dipth
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
Here is my template:
<%= date_select f, :birthday, builder: fn b -> %>
<%= b.(:day, prompt: "", class: "custom-select") %> /
<%= b.(:month, prompt: "", class: "custom-select") %> /
<%= b.(:year, options: Timex.now.year..(Timex.now.year - 100), prompt: "", class: "custom-select") %>
<% end %>
Here is my controller:
def update(conn, %{"user" => user_params}) do
user = Guardian.Plug.current_resource(conn)
changeset = User.changeset(user, user_params)
case Repo.update(changeset) do
{:ok, _user} ->
conn
|> put_flash(:success, gettext("Profile updated!"))
|> redirect(to: public_profile_path(conn, :show, user))
{:error, changeset} ->
conn
|> render("edit.html", changeset: changeset)
end
end
I can successfully submit the form, but the birthday is never written to the database
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 4 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dipth
You are right. Changing the column in the database to
:datefixes 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…
dsissitka
I wonder if you need to use
field :birthday, :date.I wonder if that’s because you’re using
:utc_datetimeand you aren’t passing in a time.dipth
It appears that there is some sort of implicit validation taking place since
f.errors[:birthday]in the template returns “is invalid”I have also tried using Timex like so:
which just gives an error:
Trying with a Timex date field instead:
gives another error:
radar
What do the logs show when that action is hit?