Elixir Date.diff / 2 - undefined or private

I am new to Elixir and trying to run some scripts from elixir documentation, testing the Date structure gave strange result because it    Date.compare(~D[2016-04-16], ~D[2016-04-28])

returns: lt and when I try to run Date.diff(~D[2016-04-16], ~D[2016-04-28])

I get this error

(UndefinedFunctionError) function Date.diff/2 is undefined or private
(elixir) Date.diff(~D[2016-04-16], ~D[2016-04-28])

      

+3


source to share


2 answers


Date.diff/2

was added in Elixir 1.5 (as you can see here ). I'm sure you are using the previous version. By running elixir -v

, you can check which version is installed.



+1


source


Date.compare

works correctly. :lt

is not an error code, but rather a symbol indicating the result of the comparison.

Any comparison between two dates will yield one of the following three characters:



  • :lt

    - "Less than"
  • :gt

    - "More than"
  • :eq

    - "Equal"

If you need to get the difference in dates as the number of days (for example Date.diff

), you will need to upgrade to Elixir> 1.4.5.

0


source







All Articles