zoukankan      html  css  js  c++  java
  • 关于SqlServer数据库日期函数

    1、获取当前时间 select getdate()

    2、截取需要的值

    select datepart(year,getdate())

    select datepart(month,getdate())

    select datepart(day,getdate())

    select datepart(hour,getdate())

    select datepart(minute,getdate())

    select datepart(second,getdate())

    select datepart(week,getdate())

    3、在日期中添加或减去指定的时间间隔

    select dateadd(year,3,getdate()) --获取当前时间,往后推迟三年

    select dateadd(month,3,getdate()) --获取当前时间,往后推迟三个月

    select dateadd(day,3,getdate()) --获取当前时间,往后推迟三天

    select dateadd(hour,3,getdate()) --获取当前时间,往后推迟三小时

    select dateadd(minute,3,getdate()) --获取当前时间,往后推迟三分钟

    select dateadd(second,3,getdate()) --获取当前时间,往后推迟三秒钟

    4、返回两个日期之间的时间

    select datediff(year,'2001-08-19',getdate()) --2001-08-19和当前时间之间差多少年

    select datediff(month,'2001-08-19',getdate()) --2001-08-19和当前时间之间差多少月

    select datediff(day,'2001-08-19',getdate()) --2001-08-19和当前时间之间差多少天

    5、用不同的格式显示日期/时间

    select convert(char,getdate(),8)  --显示当前时-分-秒

    select convert(char,getdate(),10) --显示当前月-日-年,显示形式“08-19-11”

    select convert(char,getdate(),11) --显示当前年-月-日,显示形式“11/08/19”

    select convert(char,getdate(),14) --显示当前时-分-秒-毫秒,显示形式“14:54:57:090”

    注:参数1-14随意。

    国泰民安
  • 相关阅读:
    Linux中more命令的实现
    hdu1392 Surround the Trees 凸包
    陈耀烨必将开启属于自己的围棋时代
    此文胜过听三年的培训课
    [置顶] 【持续更新中】推荐工具包
    【读书笔记】《未来闪影》罗伯特·J·索耶
    Redis util
    591
    多线程
    [Usaco2008 Feb]Meteor Shower流星雨
  • 原文地址:https://www.cnblogs.com/jirglt/p/2544028.html
Copyright © 2011-2022 走看看