I'm currently trying to check if the date time format in a certain column of a csv file is in the correct format.
I am using this:
if pd.to_datetime(df['date'], format='%Y-%m-%d %H:%M:%S', errors ='raise'):
print('date format wrong')
However dates if the format %Y/%m/%d %H:%M:%S still gets through.
Any advice out there? Thanks in advance!
Added by Scott Boston:
s = pd.Series(['2020-01-01 12:01:00','2020/01/01 12:02:00'])
pd.to_datetime(s, format='%Y-%m-%d %H:%M:%S', errors='raise')
Output:
0 2020-01-01 12:01:00
1 2020-01-01 12:02:00
dtype: datetime64[ns]