Extracting hours from a DateTime (SQL Server 2005)

后端 未结 11 544
野趣味
野趣味 2020-12-01 03:21

I can extract the month and day by using Day(Date()), Month(Date()). I can\'t extract hours, with HOUR(Date()). I get the following er

11条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 04:01

    The DATEPART() function is used to return a single part of a date/time, such as year, month, day, hour, minute, etc.

    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 
    

    Example

    select * 
    from table001
    where datepart(hh,datetime) like 23
    

提交回复
热议问题