Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello friends,

by using date time picker i get two day like 12/12/2011 and 15/12/2011 and i want to get the inbetween dates in
gridview
like

13/12/2011
14/12/2011
15/12/2011
Posted

C#
DateTime FromDate = new DateTime(2011, 12, 12);
            DateTime ToDate = new DateTime(2011, 12, 15);

            var AllDates=Enumerable.Range(1, ToDate.Subtract(FromDate).Days).Select(i => FromDate.AddDays(i));

Assign this AllDates to datagridview data source.
 
Share this answer
 
I assume you are getting the start and end dates from two DateTimePickers, so then I would do something like this:

C#
DateTime startDate = dtpStart.Value;
            DateTime endDate = dtpEnd.Value;
            int numberOfDays = (endDate - startDate).Days;
            List<DateTime> days = new List<DateTime>();
            for(int i = 1; i <= numberOfDays; i++)
            {
                days.Add(startDate.AddDays(i));
            }


That will give you a List<DateTime> of all the days in between, excluding the start date as in your example.

Hope this helps
 
Share this answer
 
there is a date difference function in sql server

datdiff(startDate,EndDate)
 
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