Python date.resolution and datetime.resolution

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.

Practise Python date and time resolution

Run the examples, change date values, compare one-day and one-microsecond increments, and complete short self-checking exercises.

Open Python date resolution practice in Google Colab View notebook on GitHub

Uses only the standard library. Publish the companion notebook in plus2net/Python-basics before making these links live.

What does .resolution mean in Python?

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.

TypeResolutionMeaning
datetimedelta(days=1)One calendar day
datetimetimedelta(microseconds=1)One microsecond
timetimedelta(microseconds=1)One microsecond
timedeltatimedelta(microseconds=1)One microsecond

datetime.resolution: smallest represented time interval

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.

Using the resolution of a fixed datetime object

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

Compare date, datetime, time and timedelta

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

Add the smallest date increment

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.

Add one microsecond and cross a day boundary

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

Convert resolution to seconds

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.

Class attribute vs instance attribute

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

What resolution does not tell you

Important: 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

Inspect the system clock resolution

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.

Use case: event logging systems

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.

Use case: financial transactions

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.

Common mistakes and troubleshooting

ProblemCauseSolution
date.resolution() raises an errorresolution is a timedelta attribute, not a functionWrite date.resolution without parentheses
date.resolution prints 1 day, 0:00:00Python displays a timedelta durationRead it as one day, not a clock time
datetime.resolution seems to promise precisionType granularity and real clock accuracy are differentInspect platform clock details for clock questions
Two events have the same timestampClock readings can repeatAdd a unique event ID or database key
date does not include hours or secondsdate stores a day onlyUse 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

Practice exercises

  1. Print the resolution for date, datetime, time, and timedelta.
  2. Starting with date(2024, 12, 31), add date.resolution. What is the result?
  3. Convert datetime.resolution into seconds using total_seconds().
  4. Make a fixed datetime with microsecond value 999999, add one resolution increment, and observe the rollover.
  5. Explain why two log records need unique IDs even if both have microsecond timestamps.

Try these tasks in the Colab practice notebook or review the GitHub notebook.

Frequently asked questions

Is Python date.resolution a method?

No. It is a read-only class attribute whose value is a timedelta. Access date.resolution, not date.resolution().

What is the resolution of datetime.date?

One full day, represented as 1 day, 0:00:00.

What is the resolution of datetime.datetime?

One microsecond (0:00:00.000001), not one millisecond.

Does datetime.now() measure time to one-microsecond accuracy?

Not necessarily. The type supports microseconds, but the actual clock accuracy and observed increment are platform-dependent.

Can resolution be changed with an argument?

No. It is a characteristic of the type. You can perform arithmetic with different timedelta increments when needed.

How is resolution different from timedelta?

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.

Back to top ↑




Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer