Wednesday, April 30, 2008

Compare two Dates in SQL Server

The below QUERY can compare two dates in sql server. In that query CONVERT() function is exist. Date value is changed into varchar data type by using CONVERT() function . Here we change the DATETIME data type into varchar. So we got exact date alone. The query as follows....

SELECT *
FROM Login_Attendance
WHERE (DATEDIFF(day, CONVERT(varchar(10), currdate, 101), CONVERT(varchar(10), '4/25/2008', 101)) = 0)

Here,

101----> denotes the required format(mm/dd/yyyy) of the date

For eg:
currdate='4/25/2008 2:23:34 PM'

No comments: