title: How to get the difference between two chrono dates?
body: <p>I'd like to get a &quot;time-span&quot; difference between today <code>08/11/2020</code> and <code>01/01/1970</code> in such format:</p>
  <pre class="lang-none prettyprint-override"><code>Timespan:
  50 year(s) 10 month(s) 7 day(s)
  </code></pre>
  <p>The code below correctly calculates this for: <code>today - 01/01/1970</code>. However, it fails miserably for input like <code>23/12/1970</code> giving:</p>
  <pre class="lang-none prettyprint-override"><code>50 year(s) -1 month(s) -15 day(s)
  </code></pre>
  <p>Whereas the expected result is <code>49 year(s) 10 month(s) 16 day(s)</code>.</p>
  <p>More dates to test:</p>
  <ul>
  <li><p><code>09/01/1985</code></p>
  <p>Got: <code>35 year(s) 10 month(s) -1 day(s)</code> but expected <code>35 year(s) 9 month(s) 30 day(s)</code>.</p>
  </li>
  <li><p><code>24/02/1936</code></p>
  <p>Got: <code>84 year(s) 9 month(s) -16 day(s)</code> but expected <code>84 year(s) 8 month(s) 15 day(s)</code>.</p>
  </li>
  </ul>
  <p>Cargo.toml:</p>
  <pre><code>[package]
  name = &quot;relative-delta&quot;
  version = &quot;0.1.0&quot;
  authors = [&quot;baduker&quot;]
  edition = &quot;2018&quot;
  
  [dependencies]
  chrono = &quot;0.4.19&quot;
  </code></pre>
  <p>Code:</p>
  <pre><code>use chrono::{NaiveDateTime, DateTime, Utc, Datelike};
  
  fn main() {
      let date_string = &quot;23/12/1970&quot;;
      let naive_date = chrono::NaiveDate::parse_from_str(date_string, &quot;%d/%m/%Y&quot;).unwrap();
      let naive_datetime: NaiveDateTime = naive_date.and_hms(0, 0, 0);
      let date = DateTime::&lt;Utc&gt;::from_utc(naive_datetime, Utc);
  
      let years = Utc::now().year() - date.year();
      let months = Utc::now().month() as i64 - date.month() as i64;
      let days = Utc::now().day() as i64 - date.day() as i64;
  
      println!(&quot;Timespan:\n{} year(s) {} month(s) {} day(s)&quot;, years, months, days);
  }
  </code></pre>