date.resolution is the smallest difference between two distinct datetime.date values: one day. It is an attribute (a timedelta value), not a function to call with parentheses.
from datetime import date
dt = date.today().resolution
print(dt)
Output:
1 day, 0:00:00
The value is the same every day: changing the current date does not change the class's resolution.
Run the examples, change date values, compare one-day and one-microsecond increments, and complete short self-checking exercises.
Uses only the standard library. Publish the companion notebook in plus2net/Python-basics before making these links live.
The resolution class attribute describes the smallest possible difference between two non-equal values of that type. date stores whole calendar days, whereas datetime and time support microseconds. It does not mean how accurately your computer measures elapsed time.
| Type | Resolution | Meaning |
|---|---|---|
date | timedelta(days=1) | One calendar day |
datetime | timedelta(microseconds=1) | One microsecond |
time | timedelta(microseconds=1) | One microsecond |
timedelta | timedelta(microseconds=1) | One microsecond |
Unlike date, a datetime value contains a time component. This is the original example using datetime.now():
from datetime import datetime
dt = datetime.now().resolution
print(dt)
Output:
0:00:00.000001
The displayed timedelta equals one microsecond, which is one millionth of a second. This describes storage granularity, not clock accuracy.
The result does not depend on whether the datetime is from 2019, 2024, or today. This preserves the original date-with-time demonstration:
import datetime
# Year, Month, date, Hour, Minute, Second, microsecond
dt = datetime.datetime(2019,12,31,23,59,59,345234)
print(dt.resolution)
Output:
0:00:00.000001
All four types expose a resolution attribute. Although the printed format looks like a time, each resolution is a timedelta duration.
from datetime import date, datetime, time, timedelta
print("date:", date.resolution)
print("datetime:", datetime.resolution)
print("time:", time.resolution)
print("timedelta:", timedelta.resolution)
Output:
date: 1 day, 0:00:00
datetime: 0:00:00.000001
time: 0:00:00.000001
timedelta: 0:00:00.000001
Use date.resolution like any other timedelta. The leap-year transition provides a simple example:
from datetime import date
start = date(2024, 2, 28)
print(start + date.resolution)
print(start + 2 * date.resolution)
Output:
2024-02-29
2024-03-01
The date type advances in whole calendar days; Python handles the leap day automatically. Read more in the Python timedelta tutorial.
A datetime increment can move into the next second or day when it reaches a boundary.
from datetime import datetime
end = datetime(2024, 2, 29, 23, 59, 59, 999999)
print(end + datetime.resolution)
Output:
2024-03-01 00:00:00
Since resolution is a timedelta object, you can call total_seconds().
from datetime import date, datetime
print(date.resolution.total_seconds())
print(datetime.resolution.total_seconds())
Output:
86400.0
1e-06
One day is 86,400 seconds; one microsecond is 0.000001 seconds.
You can access resolution on the class or on a value. The result is identical; you do not need to call today() or now() just to read it.
from datetime import date, datetime
print(date.resolution == date.today().resolution)
print(datetime.resolution == datetime.now().resolution)
print(type(date.resolution).__name__)
Output:
True
True
timedelta
datetime.resolution is not a measurement of the actual precision, accuracy, or uniqueness of timestamps returned by datetime.now(). Separate events can have identical timestamps, even though the data type supports microseconds.You can compare the fixed representable increment with an observed difference between two specific datetimes. The observed difference can be much larger than one microsecond.
from datetime import datetime
first = datetime(2024, 7, 1, 10, 0, 0, 100000)
second = datetime(2024, 7, 1, 10, 0, 0, 104000)
print("Type resolution:", datetime.resolution)
print("Observed difference:", second - first)
Output:
Type resolution: 0:00:00.000001
Observed difference: 0:00:00.004000
To inspect a platform clock, use time.get_clock_info(). Its reported resolution depends on the environment and is separate from the datetime type's resolution. For benchmarking elapsed durations, prefer time.perf_counter() or time.perf_counter_ns().
import time
info = time.get_clock_info("time")
print("Clock resolution (seconds):", info.resolution)
print("Datetime type resolution (microseconds):", 1)
The first value depends on the operating system. It should not be presented as a fixed number in a tutorial.
In a log, datetime.resolution tells you the representable increment, not the accuracy of logged events. Use timezone-aware UTC timestamps, and record an additional unique identifier if distinct events must be unambiguously identified.
This short example preserves the original logging concept:
from datetime import datetime
resolution = datetime.now().resolution
print(resolution) # One microsecond of representable granularity
Output:
0:00:00.000001
For a practical record, combine the timestamp with a unique event ID rather than assuming microseconds alone prevent collisions:
from datetime import datetime, timezone
from uuid import uuid4
record = {
"event_id": str(uuid4()),
"timestamp": datetime.now(timezone.utc).isoformat(timespec="microseconds"),
"event": "login"
}
print(record["event"])
print("ID present:", bool(record["event_id"]))
Output:
login
ID present: True
The timestamp and ID values change each run. A random UUID is useful for practical uniqueness, but the correct approach for guaranteed uniqueness is an enforced unique key in your database.
Financial systems may store microsecond-formatted timestamps for analysis and ordering, but datetime.resolution alone cannot guarantee a unique or correctly ordered transaction record. Persist a dedicated transaction ID, use transaction-safe database constraints, and define the authoritative ordering mechanism.
from datetime import datetime, timezone
transaction = {
"transaction_id": "TXN-000251",
"recorded_at": datetime(2024, 7, 1, 10, 30, 0, 123456, tzinfo=timezone.utc),
"amount": 125.50
}
print(transaction["transaction_id"])
print(transaction["recorded_at"].isoformat())
Output:
TXN-000251
2024-07-01T10:30:00.123456+00:00
For real financial applications, use an appropriate decimal type for money and secure transaction workflows; this example only demonstrates timestamp representation.
| Problem | Cause | Solution |
|---|---|---|
date.resolution() raises an error | resolution is a timedelta attribute, not a function | Write date.resolution without parentheses |
date.resolution prints 1 day, 0:00:00 | Python displays a timedelta duration | Read it as one day, not a clock time |
datetime.resolution seems to promise precision | Type granularity and real clock accuracy are different | Inspect platform clock details for clock questions |
| Two events have the same timestamp | Clock readings can repeat | Add a unique event ID or database key |
date does not include hours or seconds | date stores a day only | Use datetime to represent both date and time |
from datetime import date
try:
date.resolution() # Incorrect: a timedelta is not callable
except TypeError:
print("Use date.resolution without parentheses")
Output:
Use date.resolution without parentheses
resolution for date, datetime, time, and timedelta.date(2024, 12, 31), add date.resolution. What is the result?datetime.resolution into seconds using total_seconds().999999, add one resolution increment, and observe the rollover.Try these tasks in the Colab practice notebook or review the GitHub notebook.
No. It is a read-only class attribute whose value is a timedelta. Access date.resolution, not date.resolution().
One full day, represented as 1 day, 0:00:00.
One microsecond (0:00:00.000001), not one millisecond.
Not necessarily. The type supports microseconds, but the actual clock accuracy and observed increment are platform-dependent.
No. It is a characteristic of the type. You can perform arithmetic with different timedelta increments when needed.
A timedelta is a duration; the resolution attribute itself is a timedelta describing the smallest representable difference for the type.
Finished reading? Return to the Colab and GitHub practice notebook.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.