zoukankan      html  css  js  c++  java
  • sql日期操作

    日期格式化函数

    Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
    Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06
    Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16
    Select CONVERT(varchar(100), GETDATE(), 3): 16/05/06
    Select CONVERT(varchar(100), GETDATE(), 4): 16.05.06
    Select CONVERT(varchar(100), GETDATE(), 5): 16-05-06
    Select CONVERT(varchar(100), GETDATE(), 6): 16 05 06
    Select CONVERT(varchar(100), GETDATE(), 7): 05 16, 06
    Select CONVERT(varchar(100), GETDATE(), 8): 10:57:46
    Select CONVERT(varchar(100), GETDATE(), 9): 05 16 2006 10:57:46:827AM
    Select CONVERT(varchar(100), GETDATE(), 10): 05-16-06
    Select CONVERT(varchar(100), GETDATE(), 11): 06/05/16
    Select CONVERT(varchar(100), GETDATE(), 12): 060516
    Select CONVERT(varchar(100), GETDATE(), 13): 16 05 2006 10:57:46:937
    Select CONVERT(varchar(100), GETDATE(), 14): 10:57:46:967
    Select CONVERT(varchar(100), GETDATE(), 20): 2006-05-16 10:57:47
    Select CONVERT(varchar(100), GETDATE(), 21): 2006-05-16 10:57:47.157
    Select CONVERT(varchar(100), GETDATE(), 22): 05/16/06 10:57:47 AM
    Select CONVERT(varchar(100), GETDATE(), 23): 2006-05-16
    Select CONVERT(varchar(100), GETDATE(), 24): 10:57:47
    Select CONVERT(varchar(100), GETDATE(), 25): 2006-05-16 10:57:47.250
    Select CONVERT(varchar(100), GETDATE(), 100): 05 16 2006 10:57AM
    Select CONVERT(varchar(100), GETDATE(), 101): 05/16/2006
    Select CONVERT(varchar(100), GETDATE(), 102): 2006.05.16
    Select CONVERT(varchar(100), GETDATE(), 103): 16/05/2006
    Select CONVERT(varchar(100), GETDATE(), 104): 16.05.2006
    Select CONVERT(varchar(100), GETDATE(), 105): 16-05-2006
    Select CONVERT(varchar(100), GETDATE(), 106): 16 05 2006
    Select CONVERT(varchar(100), GETDATE(), 107): 05 16, 2006
    Select CONVERT(varchar(100), GETDATE(), 108): 10:57:49
    Select CONVERT(varchar(100), GETDATE(), 109): 05 16 2006 10:57:49:437AM
    Select CONVERT(varchar(100), GETDATE(), 110): 05-16-2006
    Select CONVERT(varchar(100), GETDATE(), 111): 2006/05/16
    Select CONVERT(varchar(100), GETDATE(), 112): 20060516
    Select CONVERT(varchar(100), GETDATE(), 113): 16 05 2006 10:57:49:513
    Select CONVERT(varchar(100), GETDATE(), 114): 10:57:49:547
    Select CONVERT(varchar(100), GETDATE(), 120): 2006-05-16 10:57:49
    Select CONVERT(varchar(100), GETDATE(), 121): 2006-05-16 10:57:49.700
    Select CONVERT(varchar(100), GETDATE(), 126): 2006-05-16T10:57:49.827
    Select CONVERT(varchar(100), GETDATE(), 130): 18 ???? ?????? 1427 10:57:49:907AM
    Select CONVERT(varchar(100), GETDATE(), 131): 18/04/1427 10:57:49:920AM

    常用操作

    Select CONVERT(varchar(100), GETDATE(), 24): 10:57:47
    Select CONVERT(varchar(100), GETDATE(), 108): 10:57:49
    
    Select CONVERT(varchar(100), GETDATE(), 12): 060516
    Select CONVERT(varchar(100), GETDATE(), 23): 2006-05-16
    select CONVERT(varchar(12) , getdate(), 112 ) :   20040912 
    Select CONVERT(varchar(100), GETDATE(), 8): 10:57:46

    select DateName(year,GetDate()) as ''
    SELECT DateName(Quarter,GetDate()) as ''
    select  DateName(month,GetDate()) as ''
    select DateName(day,GetDate()) as ''
    select DateName(dw,GetDate()) as '星期'
    select DateName(week,GetDate()) as '周数'
    select DateName(hour,GetDate()) as ''
    select DateName(minute,GetDate()) as ''
    select DateName(second,GetDate()) as ''

    SQL根据指定月份获取当前季度

    declare @dt datetime
    set @dt = cast('2007-05-01' as datetime)
    
    select datename(yy,@dt) + '-' + right('0'+cast(3 * (datepart(qq,@dt)-1) + 1 as varchar),2) + ''
    union 
    select datename(yy,@dt) + '' + right('0'+cast(3 * (datepart(qq,@dt)-1) + 2 as varchar),2) + ''
    union
    select datename(yy,@dt) + '' + right('0'+cast(3 * (datepart(qq,@dt)-1) + 3 as varchar),2) + ''

  • 相关阅读:
    Sql Server2005 TransactSQL 新兵器学习总结之数据类型
    Sql Server2005 TransactSQL 新兵器学习总结之TOP 运算符
    Sql Server2005 TransactSQL 新兵器学习总结之TRY…CATCH
    SQL Server函数大全(三)Union与Union All的区别
    Sql Server2005 TransactSQL 新兵器学习总结之APPLY 运算符
    Sql Server2005 TransactSQL 新兵器学习总结之公用表表达式(CTE)
    SDUT 飞行棋 (概率DP & 期望)
    HDU 4276 The Ghost Blows Light (树形DP)
    POJ 2096 Collecting Bugs (概率DP & 期望 )
    HDU 4118 Holiday's Accommodation (树形DP 哎,头脑不清晰,没看懂。。。。)
  • 原文地址:https://www.cnblogs.com/tgzhu/p/8010689.html
Copyright © 2011-2022 走看看