Show post between today's date and 6 months before
I am having problems with my SQL statement SELECT
. Basically I want to return all records where the transaction date is between today's date and today's date minus 6 months.
What I've tried so far:
SELECT * FROM loan_ledger
WHERE trandate <= DATEADD(month,-6,GETDATE())
but he doesn't get the exact result. The result was dates like 2009 or 2007 being returned, but what I want is if the date today is April 9, 2012, the results should be transactions from that date (April 9, 2012) to April 9, 2012 minus 6 months ( October 9,2011). Only.
What the heck is that the results display transactions in the past and still display 2009, 2001 records which I don't want!
Can anyone help me?
source to share
Another answer is close, but if you are using BETWEEN you want to add it to the date if you want to enable today
select * from loan_ledger
where trandate BETWEEN dateadd(month,-6,getdate()) AND getdate()+1
When used between getdate, it will not be enabled today unless you reach 1.
source to share