Search code examples
python-3.xpandaspython-datetime

How to only display date component in a timestamp column - Python


I have a Pandas Dataframe that has a timestamp column. I would like to display only the date portion of it and not the hh:mm:ss portion. I tried using to_datetime function but it did not remove the time component. Could anyone assist on this. Thanks

input date : 2018-05-03 07:20:17
date = pd.to_datetime(df["FileReceivedTime"], format="%Y%m%d%")
date

Output : 2018-05-03 07:20:17

Solution

  • You can add this:

    dt.strftime('%Y/%m/%d')
    

    in

    date = pd.to_datetime(df["FileReceivedTime"], format="%Y%m%d%").dt.strftime('%Y/%m/%d')