Tuesday, 8 May 2012

How to Get Date Part from Datetime column in sql

Here you are going to learn how to get date from datetime value and also check using where class
CREATE TABLE Test
(
 ID INT,
  TblDate DATETIME
)


INSERT INTO Test VALUES(1,GETDATE());
INSERT INTO Test VALUES(2,GETDATE());


SELECT
ID,CAST(TblDate AS DATE),DATEPART(YEAR,TblDate)
FROM
Test WHERE CAST(TblDate AS DATE) = CAST('5/8/2012' AS DATE)
 



No comments:

Post a Comment