Retreive Min/Max date value from Calendar Control range

Hi,

I have a calendar control that uses SelectionMode="DayWeekMonth". I can get it to show me the dates selected in a range using Calendar.SelectedDates, but i want to obtain the minimum and maximum values from the range so that i can pass these to a stored procedure.

For example if i select a week Mon 11/09/2006 - Sun 17/09/2006 I want to store 11/09/2006 in the minimum var and 17/09/2006 in the maximum var. I would do a similar thing for a month. How do i access these values from the collection?

Thanks.
liaminnesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

REA_ANDREWCommented:
here you go, you treat them as arrays

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Response.Write(Calendar1.SelectedDates[0].ToString() + " " + Calendar1.SelectedDates[Calendar1.SelectedDates.Count - 1].ToString());
    }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
liaminnesAuthor Commented:
Thanks,

I actually managed to solve it myself eventually. This is what i did it but as you say, it was to use the collection as an array.

int count = cal.SelectedDates.Count;
if (count == 7)
   {
      DateTime min = cal.SelectedDates[0];
      DateTime max = cal.SelectedDates[6];
      lbl.Text = min.ToShortDateString() + " " + max.ToShortDateString();
   }
if (count == 30)
   {
      DateTime min = cal.SelectedDates[0];
      DateTime max = cal.SelectedDates[29];
      lbl.Text = min.ToShortDateString() + " " + max.ToShortDateString();
   }
if (count == 31)
   {
      DateTime min = cal.SelectedDates[0];
      DateTime max = cal.SelectedDates[30];
                lbl.Text = min.ToShortDateString() + " " + max.ToShortDateString();
   }

And not forgetting Feb/Leap Years!!! I'd be better using the Calendar1.SelectedDates.Count - 1 as you have though.

Points are on there way to you
Thanks.
REA_ANDREWCommented:
just FYI, I have made a function to determine if a year is a leap year or not. Here you go

public bool Is_leapYear(int YearNow)
    {
        if (YearNow % 4 == 0)
        {
            if (YearNow % 100 == 0)
            {
                if (YearNow % 400 == 0)
                {
                    // Andy Says: We Have A Leap Year
                    return true;
                }
                else
                {
                    return false;
                    // Andy Says: We Do Not Have A Leap Year
                }
            }
            else
            {
                return true;
                // Andy Says: We Have A Leap Year
            }
        }
        else
        {
            return false;
            // Andy Says: We Do Not Have A Leap Year
        }
    }
liaminnesAuthor Commented:
Thanks, that'll come in handy.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.