Click here to Skip to main content
15,916,601 members
Please Sign up or sign in to vote.
1.00/5 (3 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
Comments
[no name] 21-Jan-13 2:52am    
What is the datatype of your DOB in database?

var query="select * from birthdays where DOB between todays date and todaysdate.AddDays(15).
then you will get all the date information between 15 days from today.
 
Share this answer
 
Comments
fjdiewornncalwe 21-Jan-13 14:14pm    
+5. The simple, correct solution.
You can debug the application and verify yourself,
First modify your statement as follows
C#
var query="select * from birthdays where DOB='"+ DateTime.Today.AddDays(15)+"'";
SqlCommand cmd = new SqlCommand(query,cnn);

Then copy the value of "query" variable and paste it into your SQL server and check it is working their.
 
Share this answer
 
Create a function in SQL like given below

//////////////////////////////////////////////////////////////
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