Home > Software engineering >  finding date from pandas datetimeobject
finding date from pandas datetimeobject

Time:06-29

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. Thanks!

CodePudding user response:

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)

CodePudding user response:

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