I want to display records for the last 4 months from the current date.
I do not want to consider time
How can I get only a part of the date from the query below?
where OrderDate >= DATEADD(month, -4, GETDATE())
Why not use the simple DATEDIFF function
where DATEDIFF(MM, OrderDate, GETDATE()) < 4
If you are using SQL Server 2008, try converting GETDATE()to DATEdirectly.
GETDATE()
DATE
WHERE OrderDate >= DATEADD(month, -4, CONVERT(date, GETDATE()))
http://sqlfiddle.com/#!3/df444/2
DATE, : DATETIME CHAR, DATETIME, :
DATETIME
CHAR
SELECT CONVERT(DATETIME, CONVERT(CHAR(8), GETDATE(), 112), 112) -- ----------------------- -- 2014-02-25 00:00:00.000
( ), .