I just need a where condition in my select statement where AddedDate is less than or within the 3 month backet. Like
Select * FROM My Table where AddedDate DateDiff of DateNow less than 3 months
In SQL Server, you can use the DATEADD() function to get last 3 months (or n months) records.
Instead of approximating the "current" date by selecting the MAX(date) the code could reference CAST(GETDATE() as DATE) to access the system datetime and cast it as type DATE. where [date] > dateadd(month, -6, cast(getdate() as date));
For that you should say WHERE my_float >= 1 AND my_float < 3 . Equally, in your case, if you wanted exactly one month, your parameters would both be 20120101 , but there is NO time between those values.
Use DATEADD():
Select * FROM My Table where AddedDate>=DATEADD(m, -3, GETDATE())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With