How to add to a Date in Elixir Ecto

1.2k views Asked by At

I need to store today + 1 day in an Ecto.DateTime variable for storing in a database, but for the life of me I can't find how to do that. The Timex library is popular in Elixir, and in older versions I found a Timex.Date.add() but that is gone in the current version.

1

There are 1 answers

0
Dogbert On BEST ANSWER

With timex 3.0, you can use Timex.add/2 and Timex.Duration.from_days/1:

iex(1)> Ecto.DateTime.utc
#Ecto.DateTime<2016-12-25 14:47:07>
iex(2)> Timex.add(Timex.now, Timex.Duration.from_days(1)) |> Ecto.DateTime.cast!
#Ecto.DateTime<2016-12-26 14:47:08.996803>