回覆列表
  • 1 # 使用者5007521561936

    SQL Server

    使用DATEADD 函式 日期部分縮寫

    日期部分 縮寫

    year yy, yyyy

    quarter qq, q

    month mm, m

    dayofyear dy, y

    day dd, d

    week wk, ww

    weekday dw, w

    hour hh

    minute mi, n

    second ss, s

    millisecond ms

    1>

    2> SELECT "現在" AS [日期], GETDATE() AS [資料]

    3> UNION ALL

    4> SELECT "下一秒" AS [日期], DATEADD(ss, 1, GETDATE() ) AS [資料]

    5> UNION ALL

    6> SELECT "下一分" AS [日期], DATEADD(mi, 1, GETDATE() ) AS [資料]

    7> UNION ALL

    8> SELECT "下一小時" AS [日期], DATEADD(hh, 1, GETDATE() ) AS [資料]

    9> UNION ALL

    10> SELECT "明天" AS [日期], DATEADD(dd, 1, GETDATE() ) AS [資料]

    11> UNION ALL

    12> SELECT "下週" AS [日期], DATEADD(ww, 1, GETDATE() ) AS [資料]

    13> UNION ALL

    14> SELECT "下月" AS [日期], DATEADD(mm, 1, GETDATE() ) AS [資料]

    15> UNION ALL

    16> SELECT "下季度" AS [日期], DATEADD(qq, 1, GETDATE() ) AS [資料]

    17> UNION ALL

    18> SELECT "明年" AS [日期], DATEADD(yy, 1, GETDATE() ) AS [資料]

    19> go

    日期 資料

    -------- -----------------------

    現在 2010-08-31 17:20:57.950

    下一秒 2010-08-31 17:20:58.950

    下一分 2010-08-31 17:21:57.950

    下一小時 2010-08-31 18:20:57.950

    明天 2010-09-01 17:20:57.950

    下週 2010-09-07 17:20:57.950

    下月 2010-09-30 17:20:57.950

    下季度 2010-11-30 17:20:57.950

    明年 2011-08-31 17:20:57.950

    (9 行受影響)

    PS: 上面的 SQL 執行於 2010-08-31 17:20:57.950

    不是今天執行的。

  • 中秋節和大豐收的關聯?
  • 企業破產瞭如何安置職工?