Reputation: 25
I am having trouble to find the records which are with in a 30 days range in a given date
Ex: I have record with the date of 10/31/2014 and I have a given specific Due date of 11/28/2014.
I would like to retrieve this record(10/31/2014) when my current date is 10/28/2014 until my current date becomes 11/28/2014 (i.e with in 30 days range). If my current date is 11/29/2014 then I no need retrieve this record.
I have spend almost 3 hours of my time. It will be greatly appreciated if you can give me a query for it.
Thanks, VJ.
Upvotes: 0
Views: 1775
Reputation: 1270873
The general format is something to the effect of:
where duedate >= CURRENT_DATE - interval '30' day and duedate <= CURRENT_DATE
This is standard syntax and will work in MySQL and Postgres. An Oracle equivalent is:
where duedate >= trunc(sysdate) - 30 day and duedate <= trunc(sysdate)
And a SQL Server equivalent is:
where duedate >= cast(getdate() - 30 as date) and duedate <= cast(getdate() as date)
Upvotes: 3