0
votes

In a table called mt, how do I convert the Sun column to date format from nvarchar(50)?

Sun
------------------------
Sunday, March 24, 2019

I tried the below query but it errored out.

SELECT CONVERT(DATETIME,Sun,109) FROM [mt]

Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.

1

1 Answers

2
votes

I think this will work:

select convert(date, stuff(sun, 1, charindex(',', Sun) + 1, ''))