I want to get the records of last month based on my db table [member] field "date_created".
What's the sql to do this?
For clarification, last month - 1/8/2009 to 31/8/2009
If today is 3/1/2010, I'll need to get the records of 1/12/2009 to 31/12/2009.
In Sql server for last one month:
If you are looking for last month so try this,
If you are looking for last month so try this,
A simple query which works for me is:
select * from table where DATEADD(month, 1,DATEFIELD) >= getdate()
An upgrade to mrdenny's solution, this way you get exactly last month from YYYY-MM-01
You need to check the month and year.