FlyingPickle
FlyingPickle

Reputation: 1133

finding date from pandas datetimeobject

I have a pandas object as follows:

pd.to_datetime('2022-06-12 00:00:00',infer_datetime_format = True)

I want to extract only the date from it. Is there a built in for me to strip out only the date?

I tried .dt.date but it didnt work.

Upvotes: 0

Views: 30

Answers (2)

Naveed
Naveed

Reputation: 11650

pd.to_datetime('2022-06-12 00:00:00',infer_datetime_format = True).strftime('%Y-%m-%d')
'2022-06-12'

Upvotes: 1

mozway
mozway

Reputation: 260455

You should only use dt with Series. For a single Timestamp use date():

pd.to_datetime('2022-06-12 00:00:00',infer_datetime_format = True).date()

output: datetime.date(2022, 6, 12)

Upvotes: 2

Related Questions