zoukankan      html  css  js  c++  java
  • MSSQL系列 (四):系统函数之日期和时间函数

    1.current_timestamp :获取数据库系统时间戳

    --获取数据库系统时间戳
    select current_timestamp
    go

     2.getdate() :获取数据库系统时间戳

    --获取数据库系统时间戳
    select getdate()
    go

     3.getutcdate() :获取utc时间

    --获取utc时间
    select getutcdate()
    go

     4.sysdatetime() :获取计算机的日期和时间的 datetime2(7) 值

    --获取计算机的日期和时间的 datetime2(7) 值
    --与 getdate比较而言,sysdatetime的秒的小数部分精度更高。
    select sysdatetime()
    go

     5.sysdatetimeoffset() :获取计算机的日期和时间的 datetime(7) 值, 时区偏移量包含在内

    --获取计算机的日期和时间的 datetime(7) 值, 时区偏移量包含在内
    select sysdatetimeoffset()
    go

     6.sysutcdatetime() :获取计算机的日期和时间的 datetime2(7) 值,utc时间

    --获取计算机的日期和时间的 datetime2(7) 值,utc时间
    select sysutcdatetime()
    go

     7.year() :获取指定日期的年份

    --获取指定日期的年份
    select year('2020-07-01')
    go

     8.month() :获取指定日期的月份

    --获取指定日期的月份
    select month('2020-07-01')
    go

     9.day() :获取指定日期的日

    --获取指定日期的日
    select day('2020-07-01')
    go

     10.isdate() :判断是否是日期,不是返回0,是返回1

    --判断是否是日期,不是返回0,是返回1
    select isdate('dfsfs')
    select isdate('2020-07-01')
    go

    11.switchoffset() :获取从存储的时区偏移量变为指定的新时区偏移量时得到的 datetimeoffset 值 

    --获取从存储的时区偏移量变为指定的新时区偏移量时得到的 datetimeoffset 值 
    select switchoffset(SYSDATETIMEOFFSET(),'-08:00')
    go

     12.todatetimeoffset() :获取从 datetime2 表达式转换的 datetimeoffset 值

    --获取从 datetime2 表达式转换的 datetimeoffset 值
    select todatetimeoffset(getdate(),'-08:00')
    go

     13.dateadd() :将指定的数值添加到日期部分后的日期

    --将指定的数值添加到日期部分后的日期
    select dateadd(hh,5,'2020-07-01 10:30')
    go

     14.datediff() :获取两个日期的指定日期部分的区别

    --获取两个日期的指定日期部分的区别
    select datediff(day,'2020-07-01','2020-08-01')
    go

     15.datename() :日期中指定日期部分的字符串形式

    --日期中指定日期部分的字符串形式
    select datename(dw,'2020-07-20')
    go

    16.datepart() :获取日期中指定日期部分的整数形式

    --获取日期中指定日期部分的整数形式
    select datepart(day,'2020-07-20')
    go

     ps:所有的

    --获取数据库系统时间戳
    select current_timestamp
    go
    --获取数据库系统时间戳
    select getdate()
    go
    --获取utc时间
    select getutcdate()
    go
    --获取计算机的日期和时间的 datetime2(7) 值
    --与 getdate比较而言,sysdatetime的秒的小数部分精度更高。
    select sysdatetime()
    go
    --获取计算机的日期和时间的 datetime(7) 值, 时区偏移量包含在内
    select sysdatetimeoffset()
    go
    --获取计算机的日期和时间的 datetime2(7) 值,utc时间
    select sysutcdatetime()
    go
    --获取指定日期的年份
    select year('2020-07-01')
    go
    --获取指定日期的月份
    select month('2020-07-01')
    go
    --获取指定日期的日
    select day('2020-07-01')
    go
    --判断是否是日期,不是返回0,是返回1
    select isdate('dfsfs')
    select isdate('2020-07-01')
    go
    --获取从存储的时区偏移量变为指定的新时区偏移量时得到的 datetimeoffset 值 
    select switchoffset(SYSDATETIMEOFFSET(),'-08:00')
    go
    --获取从 datetime2 表达式转换的 datetimeoffset 值
    select todatetimeoffset(getdate(),'-08:00')
    go
    --将指定的数值添加到日期部分后的日期
    select dateadd(hh,5,'2020-07-01 10:30')
    go
    --获取两个日期的指定日期部分的区别
    select datediff(day,'2020-07-01','2020-08-01')
    go
    --日期中指定日期部分的字符串形式
    select datename(dw,'2020-07-20')
    go
    --获取日期中指定日期部分的整数形式
    select datepart(day,'2020-07-20')
    go
  • 相关阅读:
    C++Primer中文版(第4版)第五章习题答案
    C++Primer中文版(第4版)第四章习题答案
    利用矩阵奇异值分解对图像进行压缩
    利用奇异值分解压缩图像
    程序莫名其妙地老死
    图像边沿平滑处理的matlab实现
    Zend Server搭建网站备注
    利用矩阵的n次方求图的连通性
    matlab增加数组元素的效率分析
    PHP语法总结
  • 原文地址:https://www.cnblogs.com/vic-tory/p/13345036.html
Copyright © 2011-2022 走看看