A date object contains only year, month, and day information. Many databases, APIs, and timestamp systems require datetime objects that include time components (hour, minute, second).
Since a date has no inherent time, you must specify one, typically midnight (00:00:00) unless your use case requires something different.
Using datetime.combine() (Recommended)
The cleanest approach combines your date with a time object using datetime.combine():
from datetime import date, datetime, time
d = date(2026, 12, 25)
dt = datetime.combine(d, time.min)
print(dt) # 2026-12-25 00:00:00
print(type(dt)) # <class 'datetime.datetime'>Output:
2026-12-25 00:00:00
<class 'datetime.datetime'>Setting a Specific Time
When you need a particular time rather than midnight:
from datetime import date, datetime, time
d = date(2026, 12, 25)
end_of_day = datetime.combine(d, time(17, 30))
print(end_of_day) # 2026-12-25 17:30:00
day_end = datetime.combine(d, time.max)
print(day_end) # 2026-12-25 23:59:59.999999
business_start = datetime.combine(d, time(9, 0, 0))
print(business_start) # 2026-12-25 09:00:00Output:
2026-12-25 17:30:00
2026-12-25 23:59:59.999999
2026-12-25 09:00:00Manual Construction
You can also construct a datetime directly from date components:
from datetime import date, datetime
d = date(2026, 12, 25)
dt = datetime(d.year, d.month, d.day)
print(dt) # 2026-12-25 00:00:00
dt = datetime(d.year, d.month, d.day, 14, 30, 0)
print(dt) # 2026-12-25 14:30:00Output:
2026-12-25 00:00:00
2026-12-25 14:30:00Adding Timezone Information
For timezone-aware datetimes:
from datetime import date, datetime, time, timezone, timedelta
d = date(2026, 12, 25)
dt_utc = datetime.combine(d, time.min, tzinfo=timezone.utc)
print(dt_utc) # 2026-12-25 00:00:00+00:00
ist = timezone(timedelta(hours=5, minutes=30))
dt_ist = datetime.combine(d, time.min, tzinfo=ist)
print(dt_ist) # 2026-12-25 00:00:00+05:30Output:
2026-12-25 00:00:00+00:00
2026-12-25 00:00:00+05:30Using zoneinfo (Python 3.9+)
from datetime import date, datetime, time
from zoneinfo import ZoneInfo
d = date(2026, 12, 25)
dt_ny = datetime.combine(d, time.min, tzinfo=ZoneInfo("America/New_York"))
print(dt_ny) # 2026-12-25 00:00:00-05:00
dt_tokyo = datetime.combine(d, time.min, tzinfo=ZoneInfo("Asia/Tokyo"))
print(dt_tokyo) # 2026-12-25 00:00:00+09:00Output:
2026-12-25 00:00:00-05:00
2026-12-25 00:00:00+09:00Converting from String Input
If your date arrives as a string, parse directly to datetime:
from datetime import datetime
date_str = "2026-12-25"
dt = datetime.strptime(date_str, "%Y-%m-%d")
print(dt) # 2026-12-25 00:00:00
dt = datetime.fromisoformat("2026-12-25")
print(dt) # 2026-12-25 00:00:00Output:
2026-12-25 00:00:00
2026-12-25 00:00:00Working with Today's Date
from datetime import date, datetime, time
today_midnight = datetime.combine(date.today(), time.min)
print(today_midnight)
now = datetime.now()
print(now)
today_noon = datetime.combine(date.today(), time(12, 0))
print(today_noon)Output:
2026-02-13 00:00:00
2026-02-13 10:24:50.622366
2026-02-13 12:00:00Common Pitfalls
Immutability
Date and datetime objects are immutable. You cannot modify them in place:
from datetime import date, datetime
d = date.today()
dt = datetime.now()
dt = datetime.combine(d, time(5, 0))Confusing date and datetime
from datetime import date, datetime
d = date(2026, 12, 25)
dt = datetime(2026, 12, 25)
print(type(d)) # <class 'datetime.date'>
print(type(dt)) # <class 'datetime.datetime'>
print(dt.hour) # 0
print(d.hour) # AttributeError: 'datetime.date' object has no attribute 'hour'Practical Example: Database Timestamps
from datetime import date, datetime, time, timezone
def date_to_db_timestamp(d: date, end_of_day: bool = False) -> datetime:
"""Convert date to timezone-aware datetime for database storage."""
if end_of_day:
t = time(23, 59, 59, 999999)
else:
t = time.min
return datetime.combine(d, t, tzinfo=timezone.utc)
start_date = date(2026, 1, 1)
end_date = date(2026, 12, 31)
query_start = date_to_db_timestamp(start_date)
query_end = date_to_db_timestamp(end_date, end_of_day=True)
print(f"From: {query_start}") # 2026-01-01 00:00:00+00:00
print(f"To: {query_end}") # 2026-12-31 23:59:59.999999+00:00Output:
From: 2026-01-01 00:00:00+00:00
To: 2026-12-31 23:59:59.999999+00:00Summary
| Goal | Code |
|---|---|
| Date to midnight | datetime.combine(d, time.min) |
| Date to specific time | datetime.combine(d, time(17, 30)) |
| Date to end of day | datetime.combine(d, time.max) |
| With timezone | datetime.combine(d, time.min, tzinfo=tz) |
| Manual construction | datetime(d.year, d.month, d.day) |