我可以通过使用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(HOUR,GETDATE())
其他回答
必须使用datepart()
like
datepart(hour , getdate())
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
作品
select convert(time,GETDATE())
试试这个吧:
SELECT CONVERT(CHAR(8),GETDATE(),108)
DATEPART()函数用于返回日期/时间的单个部分,如年、月、日、小时、分钟等。
datepart ***Abbreviation
year ***yy, yyyy
quarter ***qq, q
month ***mm, m
dayofyear ***dy, y
day ***dd, d
week ***wk, ww
weekday ***dw, w
hour ***hh
minute ***mi, n
second ***ss, s
millisecond ***ms
microsecond ***mcs
nanosecond ***ns
例子
select *
from table001
where datepart(hh,datetime) like 23