Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have today date.but i have to get next 15 days date and display it in gridview.So how to get next 15 days date ?
i have search that Adddays() is used for that ,but it is not working.

SqlCommand cmd = new SqlCommand("select * from birthdays where DOB='"+ DateTime.Today.AddDays(15)+"'",cnn);


i have try this but my dataset is empty(not display any record).
Posted
Updated 20-Jan-13 3:00am
v2
Comments
André Kraak 20-Jan-13 8:37am    
'is not working' does not tell us what is wrong.

Please provide any relevant code and specific error message?

 
Share this answer
 
SQL
CREATE FUNCTION [dbo].[GetLatest10Dates1](
 
@mydate datetime
)
RETURNS
@tbl table (mydate datetime)
AS
BEGIN
 -- Declare the return variable here
 declare @i int =0
while(@i < 15)
begin
insert into @tbl(mydate)
select @mydate+@i
set @i = @i+1
end
 -- Return the result of the function
 RETURN
 
END


//////////////////////////////////////////////////////////////
you can see the result like


SQL
Declare @dat date
set @dat='2013-01-01'

Declare @tbl table (mydate datetime,rn int)
     insert into @tbl(mydate,rn)
(Select *, row_number() over (order by mydate ) as m  From dbo.GetLatest10Dates1(cast(@dat as date)))
select * from @tbl
 
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