Comparing DateTime Structs
Remember, comparisons in Elixir using ==/2, >/2, </2 and friends are structural and based on the DateTime struct fields. For proper comparison between datetimes, use the compare/2 function.
As the DateTime docs say, you'll want to use compare/2
in order to accurately compare two DateTime
structs.
When using compare/2
, you'll get one of :lt
, :gt
, or :eq
as a result, meaning less than, greater than, or equal respectively.
Last updated