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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 convert varchar into date

Author  Topic 

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2011-12-11 : 13:55:52
How can a varchar value like "6.30.11" be converted into date format?

pnash
Starting Member

26 Posts

Posted - 2011-12-11 : 14:46:33

Select CONVERT(DATETIME,REPLACE('6.30.11', '11', '2011'),110)
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-12-11 : 15:20:05
May be safer to use conversion format 10 instead of 110 to avoid problems when date or month is 11 (such as 11/11/11), as in:

Select CONVERT(DATETIME,'6.30.11',10)
Go to Top of Page

johntech
Yak Posting Veteran

51 Posts

Posted - 2011-12-12 : 08:48:21
Also please look to this link
http://stackoverflow.com/questions/207190/sql-server-string-to-date-conversion

it contains all date formats ,so you can choose which suitable for you
Go to Top of Page
   

- Advertisement -