How to 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 it then we will convert it to date.

Python program to convert date to datetime

from datetime import date
from datetime import datetime
print(“Today’s Date: “,mdate)
print(“Current Time: “,mtime)
print(“Datetime: “, mdatetime)


Today’s Date: 2023-02-18
Current Time: 19:37:55.779312
Datetime: 2023-02-18 19:37:55.779312

Source 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.