Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 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

it will return the number of days in the current month
SQL
declare @dt datetime
set @dt = getdate()

select
	DT = @dt,
	[Days in Month] =day(dateadd(mm,datediff(mm,-1,@dt),-1))


or you can try

SQL
datediff(day, dateadd(day, 1-day(@date), @date),
              dateadd(month, 1, dateadd(day, 1-day(@date), @date)))
 
Share this answer
 
v2
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900