Display datetime without Time Component in Python (Example Code)

This tutorial explains how to display a datetime object without the time component in Python programming.

Setting up the Example

First, we have to load the datetime module, as you can see below:

import datetime                                   # Load datetime

Then we have to create a new datetime object.

x = datetime.datetime(2025, 7, 13, 11, 12, 55)    # Constructing a datetime object
print(x)
# 2025-07-13 11:12:55

Example: Applying date() Function to Delete Time of datetime

To get rid of the time part in our datetime object, we can use the date() function:

x_only_date = x.date()                            # Remove time
print(x_only_date)
# 2025-07-13

As demonstrated by the code above, the output shows our example datetime object without the time component.

Further Resources

Please find some related tutorials below.

 

Matthias Bäuerlen Python Programmer

Note: This article was created in collaboration with Matthias Bäuerlen. Matthias is a programmer who helps to create tutorials on the Python programming language. You might find more info about Matthias and his other articles on his profile page.

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top