to date time conversion is wrong

28 views Asked by At

I tried to convert a column that has this string "12/03/23 09:43 AM"

df_site['RECEIVE DATE'] = pd.to_datetime(df_site['RECEIVE DATE'], format='%Y:%b:%d')

but I get this format "2023-12-03 09:43:00" and that is wrong.

I need this format YYYY-DD-MM

1

There are 1 answers

1
ILKO19 On

pd.to_datetime follows the American convention when the format is ambiguous, where month is written before date. You can specify the format explicitly to make the format unambiguous

df['result_date']=pd.to_datetime(df['result_date']) 
df['t0']=pd.to_datetime(df['t0'])
df['t1']=pd.to_datetime(df['t1'])
df['t0']=df['t0'].apply(lambda x : x.date())
df['t1']=df['t1'].apply(lambda x : x.date())