Sunday, February 19, 2012

How to query dates

How can I query date only in a where clause and not include the time part? When I use the where below if the time part of the date entry has past then the rows are not returned.

WHERE A.Selected=1 AND A.EndDate Is Null OR A.Enddate >= GETDATE()

Thanks,there are convert functions with codes like 410,411...etc am not xactly sure which one it is..may be if yo google around you can get the snippet of code...
another way you can also try


WHERE A.Selected=1 AND A.EndDate Is Null OR
(
datepart(m,A.Enddate) >= datepart(m,GETDATE()) and
datepart(d,A.Enddate) >= datepart(d,GETDATE()) and
datepart(y,A.Enddate) >= datepart(y,GETDATE())
)

hth

No comments:

Post a Comment