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(32) to datetime datatype

Author  Topic 

avmreddy17
Posting Yak Master

180 Posts

Posted - 2008-07-05 : 10:31:55
I have a column of datatype VARCHAR(32) and the value in that is
GMT date/time , What is the good way of converting it into Eastern time and the output should of the datatype DATETIME, so that I can use the DATEDIFF function on that

20080702-13:12:07.000

Is there a better way of handling this then using the SUBSTRING function

SELECT CONVERT( DATETIME , SUBSTRING('20080703-20:00:00.922' , 1 ,8) + ' ' + SUBSTRING('20080703-20:00:00.922' , 10 ,12) )

Thanks for all the help

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-07-05 : 12:53:50
Hello,
I don't know what is better, but this looks smaller:
select convert(datetime,replace('20080703-20:00:00.922','-',' '))

Greetings
Webfred

There are 10 types of people in the world: Those who understand binary, and those who don't...
Go to Top of Page

avmreddy17
Posting Yak Master

180 Posts

Posted - 2008-07-06 : 12:06:55
Webfred

I guess yours is more clean and short.

Thanks
Go to Top of Page
   

- Advertisement -