例如: 2007-06-20 14:30:11我想得到小时数14, 请问如何取得, 多谢!

解决方案 »

  1.   

    select Convert(nvarchar(2),getdate(),4110)
      

  2.   

    select datepart(hour,'2007-06-20 14:30:11')
      

  3.   

    declare @aa datetime
    set @aa='2007-06-20 14:30:11'
    select Convert(nvarchar(2),@aa,14)
      

  4.   

    select datepart(hh,'2007-06-20 14:30:11')
      

  5.   

    --用 datepart函数select datepart(hh,getdate())--或select datepart(hour,getdate())
      

  6.   

    select datepart(hh,'2007-06-20 14:30:11')
      

  7.   

    select datepart(hour,'2007-06-20 14:30:11')--返回int类型
    select datename(hour,'2007-06-20 14:30:11')--返回nvarchar类型
      

  8.   

    DATEPART
    返回代表指定日期的指定日期部分的整数。语法
    DATEPART ( datepart , date ) 参数
    datepart是指定应返回的日期部分的参数。下表列出了 Microsoft® SQL Server™ 识别的日期部分和缩写。日期部分 缩写 
    year yy, yyyy 
    quarter qq, q 
    month mm, m 
    dayofyear dy, y 
    day dd, d 
    week wk, ww 
    weekday dw 
    Hour hh 
    minute mi, n 
    second ss, s 
    millisecond ms 
      

  9.   

    例如: 2007-06-20 14:30:11select datepart(hh,'2007-06-20 14:30:11')