简体   繁体   中英

Compare the selected dates of two aspxCalenders

I have two calenders, a StartDate Calender and an EndDate Calender, the basic rules for this are normal, the EndDate cant be before the start date, and the StartDate and EndDate cant be before today's date.

I tried this, and it didn't work.

if (EndDateCalender.SelectedDate < StartDateCalender.SelectedDate)
{
ErrorLabel.Text = "The End Date Cant Be Before the Start Date";
}

if (StartDateCalender.SelectedDate < DateTime.Now)
{
ErrorLabel.Text = "The StartDate Cant be before this day...";
}

if (EndDateCalender.SelectedDate < DateTime.Now)
{
ErrorLabel.Text = "The EndDate Cant be before this day...";
}

Ok, so i did this and it finally worked, I think the lack of an else statement for each one was the problem... Thanks for your time guys :)

    if (EndDateCalender.SelectedDate >= StartDateCalender.SelectedDate 
&& StartDateCalender.SelectedDate >= DateTime.Now 
&& EndDateCalender.SelectedDate > DateTime.Now)
{
//My Code
}
Else
{
ErrorLabel.ForeColor = System.Drawing.ColorTranslator.FromHtml("Red");
ErrorLabel.Text = " Invalid Date...";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM