How to get only part of the date when using dateadd () and getdate ()

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()) 
+3
source share
3 answers

Why not use the simple DATEDIFF function

where DATEDIFF(MM, OrderDate, GETDATE()) < 4
0
source

If you are using SQL Server 2008, try converting GETDATE()to DATEdirectly.

WHERE OrderDate >= DATEADD(month, -4, CONVERT(date, GETDATE())) 

http://sqlfiddle.com/#!3/df444/2

+4
source

DATE, : DATETIME CHAR, DATETIME, :

SELECT CONVERT(DATETIME, CONVERT(CHAR(8), GETDATE(), 112), 112)
-- -----------------------
-- 2014-02-25 00:00:00.000

( ), .

0
source

All Articles