Content · Programming · Python

Python Understand Dates, Times, Durations, and Timestamps

Distinguish a calendar date, a clock time, a duration and an instant.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Distinguish a calendar date, a clock time, a duration and an instant.

How It Works


A date such as 2026-10-17 does not specify an instant. A time of day such as 14:30 also needs a date and zone to identify an instant. timedelta represents elapsed days, seconds and microseconds; aware datetime values can represent moments across time zones.

For repeated local appointments, account for daylight-saving transitions separately from fixed elapsed durations.

Step-by-Step Example


from datetime import date, time, datetime, timedelta, timezone

meeting_date = date(2026, 10, 17)
meeting_time = time(14, 30)
start = datetime.combine(meeting_date, meeting_time, tzinfo=timezone.utc)
end = start + timedelta(minutes=45)
print(end.isoformat())

Understanding the Example


  • The expression 'date(2026, 10, 17)' supplies the value stored as 'meeting_date'. This value is then used or checked by the later statements.
  • The expression 'time(14, 30)' supplies the value stored as 'meeting_time'. This value is then used or checked by the later statements.

A successful run of this example prints the following output:

2026-10-17T15:15:00+00:00

Where This Fits in a Real Program


For event timestamps, distinguish the displayed local clock from the instant that it represents. Store or exchange an unambiguous aware value, then convert it when displaying it to a user. For repeated calendar appointments, use a geographic timezone so daylight-saving rules are not lost.

Practice: Try It Yourself


Create a 90-minute session using timedelta and print its start and end times.

For this exercise, predict the result before running the changed code. Then explain the difference between the original and modified cases using the actual values, not just whether the program completed.

Further Reading


Read the official Python documentation for complete parameters, return types and exceptions.

Common Beginner Mistakes


  • Treating a clock reading without a date or timezone as a unique point in time.
  • Assuming timedelta represents a calendar month of fixed length.

Key Takeaways


  • Distinguish a calendar date, a clock time, a duration and an instant.
  • A date such as 2026-10-17 does not specify an instant.
  • For repeated local appointments, account for daylight-saving transitions separately from fixed elapsed durations.
Share this resourceSend this page to someone who may find it useful.