我可以通过使用day (Date()), month (Date())来提取月和日。我不能提取小时,HOUR(Date())。我得到以下错误。
'HOUR' is not a recognized built-in function name.
我怎样才能抽出时间?
我可以通过使用day (Date()), month (Date())来提取月和日。我不能提取小时,HOUR(Date())。我得到以下错误。
'HOUR' is not a recognized built-in function name.
我怎样才能抽出时间?
当前回答
必须使用datepart()
like
datepart(hour , getdate())
其他回答
使用datepart。
例如:
datepart(hh, date)
试试这个吧:
DATEPART(HOUR,GETDATE())
必须使用datepart()
like
datepart(hour , getdate())
SELECT DATEPART(HOUR, GETDATE());
DATEPART文档
select case when [am or _pm] ='PM' and datepart(HOUR,time_received)<>12
then dateadd(hour,12,time_received)
else time_received
END
from table
作品