How to convert nvarchar column to datetime type in MS SQL SERVER 2008 R2

I have a nvarchar(50) column named "created_time" in MS SQL with the following string format

Thu Mar 03 09:43:25 +0000 2016

How do I convert it into a datetime type or select "created_time" as a datetime column?

Any help would be much appreciated.

Thanks and Regards, Christina

Answers


If you ignore the time zone, you can readily use convert():

select convert(datetime,
               left(stuff(stuff(created_time, 1, 4, ''), 8, 0, right(created_time, 4) + ' '), 20),
               100)

Actually, the intention here is to convert the string to the format "MMM DD YYYY HH:MI:SS", which is default format so cast() could also be used.


Need Your Help

Bootstrap toggle switch value

php jquery twitter-bootstrap switch-statement

I currently have the following code with my toggle switches for a on and off state. I want to however add values to it to make a calculation and have no clue where to start. In the end there is a f...

How do you change the modal link color in Foundation?

html css zurb-foundation

I have been trying for hours to figure out how to change the color of the text link that reveals a modal in Foundation. The default color for the text is black but I want it to be the same $primary...