如何转换sql string datetime

时间:2016-04-04 06:54:24

标签: sql-server datetime

如何在 sql server 2005 中将字符串April 04, 2016 12:00:00转换/转换为DATETIME

更新我想比较这样的日期:

SELECT * 
from ZeroAndLackingRequest  
WHERE request_date BETWEEN CONVERT(DATETIME,'April 04, 2016 12:00:00',103)  
                   AND CONVERT(DATETIME,'April 04, 2016 11:59:59',103)

但它不起作用。任何想法为什么?

2 个答案:

答案 0 :(得分:1)

TextBox

OR

IsTabStop = True

For more details

答案 1 :(得分:0)

Select * from [ZeroAndLackingRequest] Z where Z.request_date =  CONVERT(datetime, 'April 04, 2016 12:00:00', 120)

记得我选择120种风格,你可以选择103或其他任何其他请看下面的链接。

有关CAST和CONVERT的完整讨论,包括不同的日期格式选项,请参阅下面的MSDN Library链接:

http://msdn.microsoft.com/en-us/library/ms187928.aspx

如果你想比较

Select * from [ZeroAndLackingRequest] Z  
where cast(Z.request_date as datetime) >= cast('April 04, 2016 12:00:00' as datetime) 
and cast(Z.request_date as datetime) < cast('April 04, 2016 11:59:59' as datetime)