What is the Timestamp.date() function in Pandas?

Overview

The date() function in Pandas is used to return the date object with the year, month, and day from a Timestamp object. It is equivalent to Python's datetime object.

Syntax

The date() function takes the syntax given below:

Timestamp.date()
Syntax for the date() function in Pandas

Parameter value

The date() function takes no parameter value.

Return value

The date() function returns a date object.

Code example

Let's look at the code below:

# A code to illustrate the date() function in Pandas
# importing the pandas library
import pandas as pd
# creating a Timestamp object
my_date = pd.Timestamp('2022-04-29T7:48:52.192548651')
# obtaining the date object from the Timestamp object
print("The date from the given Timestamp object is: ", my_date.date())

Code explanation

  • Line 3: We import the Pandas library.
  • Line 6: We create a Timestamp ( datetime) object, my_date.
  • Line 9: We obtain and print the date object from the Timestamp object, my_date by using the date() function.

Free Resources