开发者

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value

开发者 https://www.devze.com 2023-01-24 06:40 出处:网络
I want to a take the substring of a value in a column \" 2010-11-10 11:59:00\" to\"2010-11-10\": SELECT CONVERT(DATETIME, SUBSTRING(CONVERT(VARCHAR(15), CONVERT(DATETIME, export_date, 105)),0,15),101

I want to a take the substring of a value in a column " 2010-11-10 11:59:00" to "2010-11-10":

SELECT CONVERT(DATETIME, SUBSTRING(CONVERT(VARCHAR(15), CONVERT(DATETIME, export_date, 105)),0,15),101) 
  FROM TABLE

I have written the fo开发者_开发百科llowing query, but it is not resulting this error:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.


Try something like

SELECT DATEADD(dd,0, DATEDIFF(dd,0,CONVERT(DATETIME, '2010-11-10 11:59:00',101)))

Output

2010-11-10 00:00:00.000


SELECT substring(convert(varchar(15),convert(varchar(15), export_date, 105)),0,11) from

0

精彩评论

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