DateTime.add is not working. Can any one help with this

I have UTC iso datetime and I want to add 900 Second into this datetime.

I read the doc to add time into DateTime. Even given example also not working I am getting Error "UndefinedFunctionError ". Help me guys.
I don’t want to use any third-party dependency.

Elixir DateTime core code

Here is my code.

iso_datetime = DateTime.utc_now()|>DateTime.to_iso8601


{:ok, datetime, 0}= DateTime.from_iso8601(iso_datetime)

# new_datetime = DateTime.add(datetime, 900, :second, Calendar.get_time_zone_database())

new_datetime = DateTime.add(datetime, 900, :second, "Etc/UTC")


Here is result

#DateTime<2019-09-25 12:32:19.092915Z>

** (UndefinedFunctionError) function DateTime.add/4 is undefined or private
    (elixir) DateTime.add(#DateTime<2019-09-25 12:32:19.092915Z>, 900, :second, "Etc/UTC")

Whats your version of elixir, DateTime.add/4 is only available since 1.8.0 according to the documentation.

Mix 1.6.6 (compiled with OTP 19).

But how can we do this in Elixir Version “1.6.6”

Thats your mix version, but lucky you, as its bundled with and the version is locked to be the same as elixir, I can tell you that you need to upgrade your elixir to at least 1.8.0 to be able to use the function mentioned above.

Perhaps it is possible through timex, still I’d upgrade elixir.


Thanks @NobbZ
I will update my Elixir version and migrate my code to updated version.

Unless you have “imperative assignments”, there shouldn’t be any problem upgrading.

I’d suggest though, to upgrade to 1.7 first and tackle all warnings before upgrading further.