Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hiii,,,

i am making a web form in which there is textbox of To_date and From_date.so when i select to_date from the ajax calendar, if the selected date is Past date then now date. so it give alert message otherwise focus go onto next calendar.

so, how this will i achieve ?
Please Help Me.......

Thanks and Regards...
Mitesh
Posted

Try this:
C#
protected string CheckDateErrors(string dateGiven)
       {
           // let's make sure that the date entered by user
           // does not exceed the present date or goes back
           // over a year.
           // we need to try parse!
           DateTime userDate = DateTime.Parse(dateGiven);
           //DateTime userDate;

           int userYear = userDate.Year;
           int userMonth = userDate.Month;
           int userDay = userDate.Day;

           // not valid! user entered future date, can't allow this to happen
           if (userDate.CompareTo(DateTime.Now) > 0)
           {
               //this.tbBeginDate.ForeColor = Color.Red;
               //this.tbBeginDate.BorderColor = Color.Red;
               return "* Cannot Enter Future Dates;";
           }
           // date cannot be more than one year old.
           else if (userDate.CompareTo(DateTime.Now) <= 0)
           {
               int difference = DateTime.Today.Year - userYear;


               // going too far back; now allowed.
               if (userYear < (DateTime.Today.Year - 1))
               {
                   return "* Cannot Enter Past One Year: Compared Years;";
               }
               else if ((difference == 1) &&
                   (userMonth < DateTime.Today.Month))
               {
                   return "* Cannot Enter Past One Year: Compared Months;";
               }
               else if ((difference == 1) &&
                    (userMonth >= DateTime.Today.Month) &&
                    (userDay < DateTime.Today.Day))
               {
                   return "* Cannot Enter Past One Year: Compared Days";
               }
               return "none";
           }
           return "none";
       }

Found it here[^]
 
Share this answer
 
 
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