menu

Sunday 23 February 2014

Different between DateTime and DateTime2 Datatype

    If you rely want to store more fraction part of second then you should select datetime2. Here the major flexibility is you can define your own fraction part of second till 7 digit. Here the datetime and datetime2 is not different , just datetime2 is the extension of existing datetime.


Point
DateTime
DateTime2
Syntax
Datetime
Datetime (Fractional second precision)

Example
DECLARE @MyDatetime datetime
CREATE TABLE Table1 ( Column1 datetime )

DECLARE @MyDatetime2 datetime2(7)
CREATE TABLE Table1 ( Column1 datetime2(7) )

Description
Defines a date that is combined with a time of day with fractional seconds that is based on a 24-hour clock.
Defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.
Date Range
January 1, 1753, through December 31, 9999
         
0001-01-01 through 9999-12-31
January 1,1 AD through December 31, 9999 AD
Time Range
00:00:00 through 23:59:59.997
00:00:00 through 23:59:59.9999999
Precision, scale
None
0 to 7 digits, with an accuracy of 100ns. The default precision is 7 digits.
Storage size
8 byte
6 bytes for precisions less than 3; 7 bytes for precisions 3 and 4. All other precisions require 8 bytes.
Accuracy
Rounded to increments of .000, .003, or .007 seconds
100 nanoseconds
Default value
1900-01-01 00:00:00
1900-01-01 00:00:00


declare @dob datetime

set @dob=getdate()
select @dob

set @dob='2014-02-23 08:54:59.697'
select @dob

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

declare @dob2 datetime2(7)

set @dob2='2014-02-23 08:54:59.6971234'
select @dob2



declare @dob3 datetime2(7)

set @dob3=getdate()
select @dob3

No comments:

Post a Comment