How to convert date to datetime?

Question:

I have this type of date ‘20181115 0756’ and also in a diffent dataframe in this format ‘2018-11-15’. I would like to know if there is any way to convert it to datetime without the hours and minutes

date['DATE']= pd.to_datetime(date.DATE)

this converts it to 218-11-15 00:00:00 and I’d like to avoid that

What I trying to do is to calcuate the time difference between the dates in the two dataframes that I have

Thank you in advance

Asked By: Data1234

||

Answers:

You can use the following code

date['DATE'] = pd.to_datetime(date['DATE'], errors='coerce').dt.date
Answered By: Todd Burus
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.