Captain16 Captain16 - 6 months ago 17
SQL Question

SQL where Date from today minus and plus days

and I have codes like this:

select CUS_Id, CUS_Name, CUS_JoinDate

from CUSTOMER

where CUS_joinDate between '04-12-2013' and '06-12-2013'


How can I make it 'where' CUS_JoinDate will be declare as from Today Date(minus 1 month and today + 1 month)?

So every time I run the report it will depends on the current date and it will automatically minus and plus 30 days.

Thanks,

Answer

try,

WHERE CUS_joinDate BETWEEN DATEADD(mm,-1,GETDATE()) AND DATEADD(mm,1,GETDATE())