Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert Varchar to Datetime

Author  Topic 

MMMY
Starting Member

14 Posts

Posted - 2012-07-16 : 15:55:11
In SQL Server, here is a sample string:

2010-11-23@20:14:17.

That is a period at the end.

How do I convert it to Datetime format to update another column?

Thank you so much!

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-07-16 : 16:13:09
Here is one way:
DECLARE @Foo VARCHAR(100) =  '2010-11-23@20:14:17.';
SELECT CAST(REPLACE(@foo, '@', 'T') + '000' AS DATETIME)
Go to Top of Page

MMMY
Starting Member

14 Posts

Posted - 2012-07-16 : 16:17:25
Wrks perfectly! You are so helpful!
Go to Top of Page
   

- Advertisement -