Datetime資料類型之datetime2和datetimeoffset資料類型

來源:互聯網
上載者:User
SQL Server 2008 中新的日期時間類型:datetime2和datetimeoffset資料類型。

datetime2資料類型,
類似於之前的datetime類型,不過其精度比較高,可以精確到小數點後面7位(100ns),其使用文法為:datetime2(n)。使用樣本:

declare @dt as datetime2(5)
set @dt = getdate()
select @dt

datetimeoffset資料類型,加入了時區位移量部分,時區位移量表示為 [+|-] HH:MM。 HH 是範圍從 00 到 14 的 2 位元,表示時區位移量的小時數。 MM 是範圍從 00 到 59 的 2 位元,表示時區位移量的附加分鐘數。 時間格式支援到最小 100 毫微秒。 必需的 + 或 - 符號指示在 UTC(通用協調時間或格林尼治標準時間)中是加上還是減去時區位移量以擷取本地時間。使用樣本:

declare @dt as datetimeoffset(8)
set @dt = '2008-08-08 08:08:08.0 +8:00'
select @dt

和CLR資料類型之間的映射關係:

SQL 資料類型 .NET Framework 類型 System.Data.SqlDbType System.Data.DbType
date System.DateTime Date Date
time System.TimeSpan Time Time
datetime2 System.DateTime DateTime2 DateTime2
datetimeoffset System.DateTimeOffset DateTimeOffset DateTimeOffset
datetime System.DateTime DateTime DateTime
smalldatetime System.DateTime DateTime DateTime

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.