Remove time from date in pandas

Remove Time from Date in Pandas

In this tutorial, we will look at how to remove the time component from a date in pandas with the help of some examples.

Remove time from date in pandas

If you’re working with a pandas datetime type date then you can simply call the .date() function or if you’re working with a pandas series you can use the attribute to remove the time from the dates. This is similar to getting just the year or month from a pandas date. The following is the syntax:

# remove time from a pandas timestamp object
# remove time from a pandas series of dates

Note that if the date is not a pandas datetime date, you need to first covert it using pd.to_datetime() before you can use the attribute.

Let’s look at some examples of using the above syntax.

Let’s first look at how to time from a pandas datetime object. For this, apply the .date() function.

import pandas as pd

sample_date = pd.Timestamp("2020-04-16 08:30:00")
# display the date
# remove the time


2020-04-16 08:30:00

You can see that we only get the date without its time component. Also note that the type of the returned date is while the original date was a pandas timestamp object.



📚 Data Science Programs By Skill Level


Intermediate ⭐⭐⭐

Advanced ⭐⭐⭐⭐⭐

🔎 Find Data Science Programs 👨‍💻 111,889 already enrolled

Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.

<class 'pandas._libs.tslibs.timestamps.Timestamp'>
<class ''>

To remove time from dates in a pandas series, you can use the attribute on the series. Here’s an example –

# create a dataframe
df = pd.DataFrame({
    'Date': ["2020-04-16 08:30:00", "2020-07-02 12:37:24", "2021-05-11 18:00:21"]
# display the dataframe


0  2020-04-16 08:30:00
1  2020-07-02 12:37:24
2  2021-05-11 18:00:21

Before we proceed to remove the time, we first need to convert the column to pandas datetime.

# convert to datetime
df['Date'] = pd.to_datetime(df['Date'])

Now, let’s add a new column to the dataframe which contains the date without the time part.

# remove time from Date and store it in a new column
df['Date_New'] = df['Date']
# display the dataframe


                 Date    Date_New
0 2020-04-16 08:30:00  2020-04-16
1 2020-07-02 12:37:24  2020-07-02
2 2021-05-11 18:00:21  2021-05-11

You can see that resulting dates don’t have time with them. Note that the new column doesn’t have a datetime datatype.

# check the column datatypes


Date        datetime64[ns]
Date_New            object
dtype: object

With this, we come to the end of this tutorial. The code examples and results presented in this tutorial have been implemented in a Jupyter Notebook with a python (version 3.8.3) kernel having pandas version 1.0.5

Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.


  • Piyush Raj

    Piyush is a data professional passionate about using data to understand things better and make informed decisions. He has experience working as a Data Scientist in the consulting domain and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.

Scroll to Top