I have a date-time which I create like this:
Ecto.DateTime.from_erl({{2015, 3, 10}, {0, 0, 0}})
It's a Phoenix app. I want to add days to it with no any additional third-party library. How?
You can use erlang's :calendar
module to manipulate dates without additional dependencies.
A standard way of adding days would be to use :calendar.date_to_gregorian_days/1
do the addition and convert back to the tuple format with :calendar.gregorian_days_to_date/1
.
As of at least Elixir 1.5.0, you can use DateTime.add/2
to add days to a date.
# add five days to the current day
DateTime.utc_now |> DateTime.add(5*24*60*60, :second)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With