Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pythonic way to combine datetime.date and datetime.time objects

People also ask

Which of the following will create a date and time using date and time in Python?

combine() to create instances of date , datetime , and time objects. Each instance is stored in a different variable: today is a date instance that has only the year, month, and day.

Which package is used to work with date and time in Python?

Python Datetime module comes built into Python, so there is no need to install it externally. Python Datetime module supplies classes to work with date and time. These classes provide a number of functions to deal with dates, times and time intervals.


It's in the python docs.

import datetime
datetime.datetime.combine(datetime.date(2011, 1, 1), 
                          datetime.time(10, 23))

returns

datetime.datetime(2011, 1, 1, 10, 23)