views:

50

answers:

4

Hi all

I am trying to convert varchar date value to datetime format. Showing error

select CONVERT(DATETIME, Convert(varchar, 20/12/2009, 103 ),103)

error: Conversion failed when converting datetime from character string.

Geetha

+1  A: 

This should work:

select CONVERT(DATETIME, '20/12/2009', 103)

Not sure what your conversion TO varchar is for...

David M
A: 

I would say you at least have to add quotes arround the string representing the date :

select CONVERT(DATETIME, Convert(varchar, '20/12/2009', 103 ),103)

(Maybe there's another problem too : I don't have an SQL Server instance available, so I cannot test)

Pascal MARTIN
A: 

You need quotes around the string otherwise it treats it as an expression and tries to do the divisions:

select CONVERT(DATETIME, Convert(varchar, '20/12/2009', 103 ),103)

Although having said that only one Convert is really necessary so you can use

select CONVERT(DATETIME, '20/12/2009',103)
Rich
A: 

You need to quote the date string:

select CONVERT(DATETIME, Convert(varchar, '20/12/2009', 103 ),103)

And you don't need two converts. This is should be enough:

select Convert(varchar, '20/12/2009', 103 )
Oded