title: Elixir: How to sort a list of (naive) datetimes?
body: <p>I have a list of NaiveDateTimes and I want to get the most recent one. What's the easiest way to sort a list of DateTimes / NaiveDateTimes?</p>
  
  <p>I know it's unsafe to use Elixir's standard sorting rules, since it compares terms structurally rather than looking at the meaning of the dates:</p>
  
  <pre><code># UNSAFE / returns entries in incorrect order:
  [~N[2020-02-29 10:00:01], ~N[2020-03-11 10:20:00], ~N[2020-03-15 10:00:00]] |&gt; Enum.sort
  # =&gt; [~N[2020-03-11 10:20:00], ~N[2020-03-15 10:00:00], ~N[2020-02-29 10:00:01]]
  </code></pre>