Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get today's date in Pandas

Tags:

python

pandas

This was supposed a simple lookup from pandas' documentation but I've failed: How can I get today's date in pandas' TimeStamp as a local date without time component or today midnight.

I thought that TimeStamp.today() was supposed to give the desired result but instead I am getting time now, meaning following always evaluates to True:

pd.Timestamp.today() == pd.Timestamp.now() # True
like image 422
sgp667 Avatar asked Jan 25 '23 23:01

sgp667


1 Answers

Some options:

# As a timestamp
pd.Timestamp.today().floor('D') # .normalize() does the same thing
# Timestamp('2019-08-05 00:00:00')

# As a date object
pd.Timestamp.today().date()
# datetime.date(2019, 8, 5)

# As a YYYY-MM-DD string
pd.Timestamp.today().strftime('%Y-%m-%d')
# '2019-08-05'

More info.

like image 83
cs95 Avatar answered Jan 28 '23 16:01

cs95