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
 DATETIME

Author  Topic 

avmreddy17
Posting Yak Master

180 Posts

Posted - 2008-10-29 : 14:23:02
Help in converting VARCHAR to Datetime

OrderDateTime
--------------------------------
20080926 11:03:04.296309 -0400s

Output

2008-09-26 11:03:04.296

Thx

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-29 : 14:45:04
select cast(left(OrderDateTime,21) as datetime) from tabl
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-30 : 02:54:51
Also make sure that you have valid dates for first 21 characters. Use ISDATE() to check it
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/09/24/handle-isdate-with-care.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -