Convert date to datetime in Python

In this article, we are going to learn how we can convert date object to datetime. We will make use of the datetime module of Python to get the current date and time. Once we have current datetime then we will convert it to date.

Environment and requirements-
Python interpreter
datetime library

Program for date to datetime conversion

from datetime import date
from datetime import datetime
print("Today's Date is : ",mdate)
print("Current Time is : ",mtime)
print("Current Datetime is : ", mdatetime)


Today’s Date is : 2023-01-05
Current Time is : 18:01:13.274525
Current Datetime is : 2023-01-05 18:01:13.274525

Program Code Explanation

  1. First we import datetime class from datetime module.
  2. Get the current date and print the date.
  3. Get the current time and print the current time.
  4. Combine the date and time and print combined date and time.