expression
Chrono signed date difference
Subtract two dates to obtain a signed difference. Ordering matters. A signed interval differs from the standard library’s nonnegative Duration. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 3 -3 Common mistake: Discarding the sign of overdue or future intervals.
Formal Syntax & Structure
rust syntaxrust
later.signed_duration_since(earlier) -> TimeDeltaWorking Example
Example Snippetrust
fn main() { use chrono::NaiveDate; let a = NaiveDate::from_ymd_opt(2025, 4, 10).unwrap(); let b = NaiveDate::from_ymd_opt(2025, 4, 7).unwrap(); println!("{} {}", a.signed_duration_since(b).num_days(), b.signed_duration_since(a).num_days());}