Skip to content
Advertisement

String date to SQL datetime conversion ‘Mon Dec 09 2019 12:00:54’

I have a field in database which has date time saved in string format like this. Mon Dec 09 2019 12:00:54

I want to convert this to SQL Datetime.

I tried by splitting but it is not working for me.

Advertisement

Answer

SQL Server is pretty flexible about recognizing formats for date/time values, but not with the day of the week. So, let’s get rid of that:

select convert(datetime, stuff(dt_col, 1, 4, ''))

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement