Get Dates from fromdate to todate

Posted by Gopal_nivas under ASP.NET on 5/27/2011 | Points: 10 | Views : 1799 | Status : [Member] | Replies : 2
hi..


i want to get the dates based on my input..

i.e)
fromdate 10/05/2011
todate 20/06/2011

now i want to get the between dates of my from date and to date..
ie) the out put will be 11/05/2011,12/05/2011.....19/06.2011
i want to store the output dates in an array..

kindly note the inputs may vary..

how to take those dates in c#..

need ur suggestions
regards
gopal.s




Responses

Posted by: Lakn2 on: 5/30/2011 [Member] Starter | Points: 25

Up
0
Down
try using below code

sqlcommand cmd=new sqlcommand("select * from tablename where datecolumn between '"+fromdate+"' and '"+ todate+"'",cn);
sqldatareader dr;
dr=cmd.executereader();
if(dr.read())
{
//your code here
}

Thanks&Regards
LakshmiNarayana Nalluri.

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 5/30/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
You can use this function
public static DateTime[] GetDates(DateTime FromDate, DateTime ToDate)

{
if (FromDate > ToDate)
throw new ArgumentException("FromDate is greater than ToDate");
TimeSpan _tspan = ToDate.Subtract(FromDate);
if (_tspan.Days > 1)
return Enumerable.Range(1, _tspan.Days - 1).Select(d => FromDate.AddDays(d)).ToArray();
else
return null;
}

@Lakn2 here you need to generate the dates not like its already stored somewhere in database and you have to fetch it. :)

Thanks,
Debata

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response