Click here to Skip to main content
16,015,218 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
design as follows;
Name             txt_name.Text
Date of birth    textbox(calendarimage)
Mobile Number    txt_mobile.text
Wedding date     textbox(calendar image)
Email            txt_mobile.text

i am validating date of birth and wedding date is not same as current date and not more than the current date.

for that validation code as follows;
C#
DateTime DOB = Convert.ToDateTime(FromDate.SelectedDateValue);
                DateTime TodayDate = DateTime.Today;
                if (DOB.Date >= TodayDate.Date) 
                {
                   Label6.Text = ("selected date is not greater than current date");
                }

                DateTime Weddingday = Convert.ToDateTime(Todate.SelectedDateValue);
                DateTime todaydate1 = DateTime.Today;
                if (Weddingday.Date >= todaydate1.Date) 
                {
   Label6.Text = ("selected date is not greater than currentdate");
                }

INSERT BUTTON CODE AS FOLLOWS;
C#
protected void="" eventargs="" mode="hold" />   {
       Label6.Text = "";

       if (FromDate.SelectedDateValue.ToString() == "")
       {
           Label6.Text = "From date is not selected";
           return;
       }
       if (Todate.SelectedDateValue.ToString() == "")
       {
           Label6.Text = "To date is not selected";
           return;
       }

           Sql ="insert into BirthDayWish values('" + txt_name.Text + "','" + FromDate.SelectedDateValue.ToString() + "','" + txt_mobile.Text + "','" + Todate.SelectedDateValue.ToString() + "','" + txt_Email.Text + "','A')";             
        

            try
           {
               SCon.Error = "";
               SCon.ExecSql(Sql);
               if (SCon.Error.ToString() != "";)
               {
                   Label6.Text = Session["Error";].ToString();
               }
               SCon.Con.Close();
}
       catch (Exception Ex1)
       {
           Response.Write(Ex1);
       }
   }


What I have tried:

in the insert code where i put my validation code for Date of Birth and Wedding Date.

please help me.
Posted
Updated 15-Feb-23 15:00pm
v3

write the validation code wherever before inserting the values in db.....
 
Share this answer
 
Be careful with DateTime.Today regarding timezones. Ensure to compare only dates within the same zone, eg. UTC and normalize them if necessary. For wedding validation, you should take legal restrictions into account and do not accept weddings with persons < 18 years. No idea why you want to compare/validate it with the birthday. ;)
 
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