SybaseIQ - 日期函数

来源:互联网 发布:python进阶书籍 知乎 编辑:程序博客网 时间:2024/06/05 21:49
一、getdate()
    作用:
        得到服务器当前的时间

二、datepart(interval,date)
    参数:
        interval:时间的某一个部分(如时、分、秒、天、周、月、季、年)
        date:当前日期或指定日期
    作用:
        取指定时间的某一个部分,年月天时分秒
    示例:
        select datepart(yy,getdate()) --year
        select datepart(mm,'2012-05-01') --month
        select datepart(dd,getdate()) --day
        select datepart(hh,getdate()) --hour
        select datepart(mi,getdate()) --min
        select datepart(ss,getdate()) --sec
        select datepart(weekday,getdate()) --默认星期天为第一天,可通过 set datefirst 1修改为星期一为第一天

三、datediff(interval,date,date)
    参数:
        interval:时间的某一个部分(如时、分、秒、天、周、月、季、年)
        date:当前日期或指定日期
    作用:
        计算第一个日期和第二个日期在用指定的时间部分计算后的差距,第一个更大为负数
    示例:
        select datediff(day,'2008-10-1','2008-10-31') --30
        select datediff(day,'2006-12-10','2006-11-30') --10

四、dateadd(interval, number, date)
    参数:
        interval:间隔时间(如时、分、秒、天、周、月、季、年)
        number:间隔数(正数为向后+N,负数为向前-N)
        date:当前日期或指定日期
    作用:
        计算指定时间,再加上表达式指定的时间长度
    示例:
        select dateadd(hour,1,getdate()) --时
        select dateadd(minute,1,getdate()) --分
        select dateadd(second,1,getdate()) --秒
        select dateadd(day,1,getdate()) --天
        select dateadd(week,1,getdate()) --周
        select dateadd(month,1,getdate()) --月
        select dateadd(quarter,1,getdate()) --季
        select dateadd(year,1,getdate()) --年

五、convert(type,date,style)
    参数:
        type:要转换为的目标数据类型(如char、int)
        date:需要转换的日期
        style:规定的时间/日期格式的编码(如101、102)
    作用:
        把日期转换为其他的类型和指定格式的数据
    示例:
        select convert(char,getdate(),101) --'09/27/2003'
        select convert(char,getdate(),102) --'2003.11.12'
        select convert(char,getdate(),103) --'27/09/2003'
        select convert(char,getdate(),104) --'27.09.2003'
        select convert(char,getdate(),105) --'27-09-2003'
        select convert(char,getdate(),106) --'27 Sep 2003'
        select convert(char,getdate(),107) --'Sep 27, 2003'
        select convert(char,getdate(),108) --'11:16:06'
        select convert(char,getdate(),109) --'Sep 27 2003 11:16:28:746AM'
        select convert(char,getdate(),110) --'09-27-2003'
        select convert(char,getdate(),111) --'2003/09/27'
        select convert(char,getdate(),112) --'20030927'
        select convert(char,getdate(),120) --'2012-05-01 14:21:40'
 
 
 
0 0
原创粉丝点击