Thursday, May 1, 2014

Datetime and Datetime2 in MS Sql Server 2008 R2



Datetime and Datetime2 in MS Sql Server 2008 R2
---------------------------------------------------------------------- 


Datetime2 is a datatype in MS SQL server 2008 to store the date and time values. Datetime is not ansi complaint


DateTime
DateTime2
Min. Value
1753-01-01 00:00:00
0001-00-00 00:00:00
Max Value
9999-12-31 23:59:59.997
9999-12-31 23:59:59.9999999
Storage Size
8 bits
6 to 8 bits
Declaration Method
Declare @now datetime
Declare @now datetime2(7)

(1)    To find the current system date by using datetime datatype:

Declare @now datetime
@now = getdate()

(2)    To find the current system date by using datetime2 datatype:

Declare @now datetime2(7)
@now = sysdatetime()
(3)    To find the length of the data type


declare @now datetime2(2)
set @now=sysdatetime()
select DATALENGTH(@now)


No comments:

Post a Comment