
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Current Date and Time from Timestamp Object in Python Pandas
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("\nToday's Date and time...\n", 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
Advertisements