站內搜尋:Yahoo搜尋如果沒有給完整的網址,請在站內再搜尋一次!

2016-03-05

T-SQL:如何系統日期時間

SELECT   GETDATE() AS GetDate,
                  CURRENT_TIMESTAMP AS CurrentTimeStamp,
                  { fn NOW() } AS FnNow,
                  SYSDATETIME() AS SysDateTime,
                  sysutcdatetime() AS SysUtcDateTime,
                  getutcdate() AS GetUtcDate,
                  SYSDATETIMEOFFSET() AS SysDateTimeOffSet

回傳值:
2016-03-05 17:19:26.610                  (GeDate)
2016-03-05 17:19:26.610                  (CurrentTimeStamp)(符合AnsiSQL標準的函數)
2016-03-05 17:19:26.610                  (FnNow)({fn NOW()}符合ODBC規範的函數)
2016-03-05 17:19:26.6060596          (SysDateTime)
2016-03-05 09:19:26.6060596          (SysUtcDateTime)
2016-03-05 09:19:26.600                  (GetUtcDate)
2016-03-05 17:19:26.6060596 +08:00    (SysDateTimeOffSet)

其他透過ODBC函數取得的日期時間:
SELECT {fn NOW()} AS FnNow,
               {fn CURRENT_TIMESTAMP()} AS CurrentTimeStamp,
               {fn CURRENT_DATE()}as CurrentDate,
       {fn CURRENT_TIME()} as CurrentTime



取得目前的系統日期:
SELECT Convert(date, GETDATE()) AS GetDate,
           Convert(date, CURRENT_TIMESTAMP) AS CurrentTimeStamp,
  Convert(date, { fn NOW() }) AS FnNow,
  Convert(date, SYSDATETIME()) AS SysDateTime,
  Convert(date, sysutcdatetime()) AS SysUtcDateTime,
  Convert(date, getutcdate()) AS GetUtcDate,
  Convert(date, SYSDATETIMEOFFSET()) AS SysDateTimeOffSet


取得目前的系統時間:
SELECT Convert(time, GETDATE()) AS GetDate,
           Convert(time, CURRENT_TIMESTAMP) AS CurrentTimeStamp,
  Convert(time, { fn NOW() }) AS FnNow,
  Convert(time, SYSDATETIME()) AS SysDateTime,
  Convert(time, sysutcdatetime()) AS SysUtcDateTime,
  Convert(time, getutcdate()) AS GetUtcDate,
  Convert(time, SYSDATETIMEOFFSET()) AS SysDateTimeOffSet



沒有留言:

張貼留言