Batu Lab NotesPractical developer guides

Represent a date-only deadline without a time component

By Batu · English technical notes

Also published in our Blogger archive.

A deadline expressed as “2026-06-30” contains a calendar day, not a clock time. Represent it with datetime.date: its value has year, month, and day components only. In the example, date.fromisoformat() parses the input string and subtracting today produces a timedelta of two days. Printing isoformat() returns the unambiguous date-only representation.

Avoid encoding a date-only rule as midnight in an arbitrary time zone unless the product also defines what happens at that boundary. A midnight datetime adds a time component, a zone decision, and potentially daylight-saving behavior that the original rule did not state. If a later workflow needs a timestamp, make the conversion at that workflow boundary with an explicitly documented time zone and policy.

The assertions verify the supplied synthetic values and the result of standard date arithmetic. They do not establish whether a deadline is inclusive, whether it is a business day, or which instant ends that date for a particular user. Those are separate domain rules. date.fromisoformat() was added in Python 3.7; the arithmetic uses date and timedelta from the standard library.

See the Python date documentation for the date type, ISO parsing, and date arithmetic.

AI-assistance disclosure: This article was drafted with AI assistance and should be reviewed in its application context.

from datetime import date, timedelta

deadline = date.fromisoformat("2026-06-30")
today = date(2026, 6, 28)
remaining = deadline - today

assert remaining == timedelta(days=2)
assert deadline.isoformat() == "2026-06-30"

print(deadline.isoformat())
print(remaining.days)
2026-06-30
2