开发者

Sql Server datetime conversion

I am trying to convert varchar da开发者_JAVA百科te 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


This should work:

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

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


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)


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)


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 )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜