C Example: Date Difference: civil-to-serial days across leap years
Uses Howard Hinnant's days_from_civil algorithm to convert a date into serial days since 1970, subtracts them for an exact day count, and also reports whole weeks plus remainder days. Tests a year boundary, a leap day (2024-02-28 to 03-01) and the same date.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
2026-11-28 -> 2027-01-01 : 34 days (4 weeks 6 days) 2000-01-01 -> 2026-11-28 : 9828 days (1404 weeks 0 days) 2024-02-28 -> 2024-03-01 : 2 days (0 weeks 2 days) 2026-11-28 -> 2026-11-28 : 0 days (0 weeks 0 days)
🧩 Keep Learning