How to convert “Thu Jun 11 00:49:35 IST 2015”
to “YYYY-MM-DD hh:mm:ss”
in SQL Server?
I tried to convert and casting but it's throwing an error
How to convert “Thu Jun 11 00:49:35 IST 2015”
to “YYYY-MM-DD hh:mm:ss”
in SQL Server?
I tried to convert and casting but it's throwing an error
A few things to note about this before I posit a solution:
YYYY-MM-DD hh:mm:ss
is ambiguous. I've converted it here to UTC.If your string is in a table called Dates with column HorribleString, then:
select
convert(varchar(100), convert(datetime2, convert(datetimeoffset,
substring(HorribleString, len(HorribleString) - 3, 4) -- Year
+ substring(HorribleString, 4, len(HorribleString) - 12) -- len(Thu ) + len( IST 2015) = 12
+ case substring(HorribleString, len(HorribleString) - 7, 3) -- Timezone
when 'IST' then ' +05:30'
else ''
end
, 109), 1), 20)
from
Dates