Reference · Dates
date.days_between
date.days_between(str, str) -> intWhat it does
The number of days from one date to another, the second minus the first: the nights of a stay, the age of an order in days. Negative when the second date is earlier. It takes dates, not date-times: for the time between two instants subtract their date.ms.
Examples
print(date.days_between("2026-11-05", "2026-11-14"))print(date.days_between("2026-11-14", "2026-11-05"))print(date.days_between("2024-01-01", "2025-01-01"), date.days_between("2023-01-01", "2024-01-01"))9-9366 365Edge cases
- The same date twice is 0.
- It counts calendar days, with no daylight saving to lose or gain an hour.
- The whole calendar fits in an int: from year 1 to year 9999 is about 3.65 million days.
print(date.days_between("2026-10-27", "2026-10-27"))print(date.days_between("2026-10-24", "2026-10-26"))print(date.days_between("0001-01-01", "9999-12-31"))023652058Errors
A date-time, text that is not a date, or any other value in either place is a runtime error, not an error value.
print(date.days_between("2026-10-27", "2026-10-27T00:00:00Z"))line 1: `date.days_between` expects a date (YYYY-MM-DD) as argument 2, got the date-time "2026-10-27T00:00:00Z" (`date.date_in` gives its date)Chaining
In a pipeline the first date comes first, so from | date.days_between(to):
print("2026-10-27" | date.days_between("2026-12-25"))let stays = [["2026-11-05", "2026-11-14"], ["2026-12-01", "2026-12-03"]]print(stays | map((s) => date.days_between(s[0], s[1])) | sum)5911See also
date.months_between, date.add_days, date.ms, date.date_in, date.weekday
Thread 0 posts
On date.days_between(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo