pub fn date_diff<DT: DateTimeParts>(from: DT, to: DT) -> DateDiffResultExpand description
Calculate the difference between two date-time values in years, months and days.
The result is positive when to is later than from, and negative when to is earlier than from.
If the two values are in different time zones, to is converted to the time zone of from first.
Then the result is calculated with the wall-clock date and time in that time zone.
Only complete days are counted, so a remaining time shorter than a day is dropped.
ยงExample
use chrono::prelude::*;
use date_differencer::{DateDiffResult, date_diff};
let date = Local.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap();
let date_after_1_year_1_day =
Local.with_ymd_and_hms(2001, 1, 2, 0, 0, 0).unwrap();
assert_eq!(
DateDiffResult {
years: 1,
days: 1,
..DateDiffResult::default()
},
date_diff(date, date_after_1_year_1_day)
);