8

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
2
  • 1
    What time format are you looking for (ISO8601, etc.)? Aug 5, 2019 at 19:39
  • 2
    Are you looking for pd.Timestamp.today().normalize()?
    – ALollz
    Aug 5, 2019 at 19:40

1 Answer 1

13

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.