Python Pandas - Get the current date and time from Timestamp object

PythonServer Side ProgrammingProgrammingPandas

Get the current date and time from Timestamp object, use the timestamp.today() method.

At first, import the required libraries −

import pandas as pd
import datetime

Create the timestamp in Pandas

timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10))

Display the Timestamp

print("Timestamp: ", timestamp)

Getting the current date and time

res = timestamp.today()

Example

Following is the code

import pandas as pd
import datetime

# set the timestamp in Pandas
timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10))

# display the Timestamp
print("Timestamp: ", timestamp)

# display the day from given timestamp
print("Day Name:", timestamp.day_name())

# getting the current date and time
res = timestamp.today()

# display the current date and time
print("
Today's Date and time...
", res) # display the current day print("Today's Day:", res.day_name())

Output

This will produce the following code

Timestamp: 2021-10-10 00:00:00
Day Name: Sunday

Today's Date and time...
2021-10-03 13:22:28.891506
Today's Day: Sunday
raja
Updated on 13-Oct-2021 07:09:22

Advertisements