Click here to Skip to main content
13,256,012 members (44,349 online)
Rate this:
Please Sign up or sign in to vote.
Anyone with help good people i need a stored procedure that i will use it to return every data in the table after five days or month after stored, so my problem is to count the days then retrieve the data that i want anyone with help
Posted 29-Sep-12 13:45pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

it will return the number of days in the current month

declare @dt datetime
set @dt = getdate()
	DT = @dt,
	[Days in Month] =day(dateadd(mm,datediff(mm,-1,@dt),-1))

or you can try

datediff(day, dateadd(day, 1-day(@date), @date),
              dateadd(month, 1, dateadd(day, 1-day(@date), @date)))
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.

For now, steps:
1. Define a date column in your table
2. When you insert any new record, populate the date column value with the DateTime of insertion
3. While retrieving data from DB, use a WHERE clause
4. WHERE clause will be driven by the date column defined. Find the difference in current datetime and the datetime stored. Driving logic would be the difference of the datetime from a given figure (let say 5 days)

Try out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171114.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100