Date datatype in SQL Server 2008

DATE DATA-TYPE:

       Date datatype is one of the new data type introduced in SQL Server 2008. It provided you the date.

Reason for this data type:

           There are lot of scenarios where, we need to get only date. In our legacy system, we dont have an option to get only date. We need to do some logic on the datetime column to get the time.

Let's play around this Date datatype in our SSMS :-)
-------------------------------------------------------------------------------------

DECLARE @VAL DATE
SELECT @VAL = GETDATE()
PRINT @VAL
 
The output is
 
2010-08-23 ( The format is  Year:Month)
-------------------------------------------------------------------------------------

Memory space taken:
       This datatype will take 3 bytes of memory.
Implicit conversion from datetime datatype:

From Datetime to Date , implicit conversion will happen. No need to explicitly convert the datatypes. Below is an example for the same.

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

DECLARE @VAL DATETIME
DECLARE @VAL1 DATE
SELECT @VAL = GETDATE()
SELECT @VAL1 = @VAL
PRINT @VAL
PRINT @VAL1

The Output is,

      Aug 23 2010 7:01PM
      2010-08-23

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

Cheers,
Venkatesan Prabu .J
http://venkattechnicalblog.blogspot.com/
Ebook Download
View all
Learn
View all