Python Glossary Русский

all Python 3datetimefunction

datetime.datetime.combine()

datetime methods

Combines a date object and a time object into a single datetime. Useful when the date and the time are stored separately.

Syntax

datetime.combine(date, time, tzinfo=time.tzinfo)

The result's tzinfo comes from the time argument, or from the explicit tzinfo parameter — date carries none — so an aware time yields an aware datetime. Pass a datetime as the first argument and its own clock and zone are silently dropped; only the calendar date survives. A common use is day boundaries: a date paired with time.min or time.max gives the start and the end of that day.

Examples

from datetime import datetime, date, time
d = date(2024, 6, 17)
t = time(9, 30)
dt = datetime.combine(d, t)
print(dt)  # 2024-06-17 09:30:00

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy