title: Dart/Flutter DateTime difference inDays error for March 31 April 1
body: <p>I am trying to get the <strong>difference in Days between two dates</strong> picked from a <code>DatePicker</code>. This works fine except for <strong>ONE single date : March 31</strong>. </p>
  
  <p>The difference in Days between two <code>DateTimes</code> is wrong by 1 day when one of the dates is March 31. I know this is due to Light Saving and March is 30.9… days long and not 31, hence I am guessing, the error. But does anyone know how to fix this other than manually checking if a date is equal to March 31 and adding one day to the result ?</p>
  
  <p>Two very simple examples that can be run in the <a href="https://dartpad.dartlang.org/" rel="noreferrer">Dart Pad</a> :</p>
  
  <pre><code>DateTime aprilFirst = DateTime(2019, 3, 30);
  DateTime marchThirtyFirst = DateTime(2019, 3, 31);
  
  print(aprilFirst.difference(marchThirtyFirst).inDays); =&gt; -1
  </code></pre>
  
  <hr>
  
  <pre><code>DateTime marchThirty = DateTime(2019, 4, 1);
  DateTime marchThirtyFirst = DateTime(2019, 3, 31);
  
  print(marchThirty.difference(marchThirtyFirst).inDays); =&gt; 0
  </code></pre>
  
  <p><strong>UPDATE</strong>: </p>
  
  <pre><code>DateTime aprilFirst = DateTime(2019, 4, 1);
  print(aprilFirst.add(Duration(days: -1))); =&gt; 2019-03-30 23:00:00.000
  </code></pre>
  
  <p>This should print 2019-03-31 23:00:00.000 !</p>
  
  <p>I tried Günter Zöchbauer's solution of making the DateTimes UTC but the results are the exact same:</p>
  
  <pre><code>DateTime aprilFirst = DateTime(2019, 4, 1).toUtc();
  DateTime marchThirty = DateTime(2019, 3, 30).toUtc();
  DateTime marchThirtyFirst = DateTime(2019, 3, 31).toUtc();
  
  print(aprilFirst.difference(marchThirtyFirst).inHours); =&gt; 23
  print(aprilFirst.difference(marchThirtyFirst).inDays); =&gt; 0
  print(marchThirty.difference(marchThirtyFirst).inHours); =&gt; -24
  print(aprilFirst.add(Duration(days: -1))); =&gt; 019-03-30 22:00:00.000Z
  </code></pre>