I’m having trouble with my SQL SELECT statement. Basically I want to return all the records where the transaction date is between today’s date and today’s date minus 6 months.
What i have tried so far is:
SELECT * FROM loan_ledger
WHERE trandate <= DATEADD(month,-6,GETDATE())
but it doesn’t get the exact result. The result was returning dates like 2009 or 2007, but what I want is, if the date today is April 9, 2012, the results must be transactions from this date (April 9, 2012) to April 9, 2012 minus 6 months (October 9,2011). Only.
What the heck is that the results are displaying transactions on the past and still displaying the 2009, 2001 records which I don’t want!
Can someone help me?
The other answer are close but if you are using BETWEEN you will want to add one to the date if you want to include today
When using between with getdate, it won’t include today unless you at 1 to it.