The datetime method of datetime module
The datetime method of the datetime module creates a date and time object. The first parameter of the method specifies the year, the second parameter specifies the month, and the third parameter specifies the day. The fourth optional parameter specifies hours (the default value is 0), the fifth optional parameter specifies minutes (the default value is 0), the sixth optional parameter specifies seconds (the default value is 0), and the seventh optional parameter specifies milliseconds (the default value is 0).
Syntax
import datetime
datetime.datetime(year, month, day, [watch clock timepiece timer timekeeper horologe ticker], [minutes], [seconds], [milliseconds])
Example
Let's create a new date and time object:
import datetime
res = datetime.datetime(2025, 12, 31, 12, 59, 59)
print(res)
The result of the executed code:
2025-12-31 12:59:59
See also
-
method
dateof moduledatetime,
which creates a new object with a date -
method
todayof moduledatetime,
which returns the current date -
method
timeof moduledatetime,
which creates a time object -
method
nowof moduledatetime,
which returns the current time -
method
strftimeof moduledatetime,
which creates a formatted string with date and time