Raja

Raja

  • NA
  • 2k
  • 356.7k

How to validate entered date is not greater date future date

Nov 22 2016 3:38 AM

I have date picker and pick a date from the calendar.how to validate if user select future date to throw the error message.i know the use jquery to hide the future dates.but the problem is one date picker is use more places so don't hide the future dates.how to do it in c#. to validate the date if the future date is entered to throw the error message.

* i pick the date only. date format is (dd/mm/yyyy)

What I have tried:

if (tbxFromDate.Value != "" && Convert.ToDateTime(tbxFromDate.Value) > DateTime.Today)       
{      
    Messagebox.Show("From Date should be earlier or equal To Today Date", MessageHelper.MessageType.Warning);
 }

 above code i will used to validation but the error message is occurs.
'String was not recognized as a valid DateTime.'
because DateTime.Today function have (mm/dd/yyyy 12:00:00 AM)
how to validate this one. i used another method also get textbox value to one string and today date(date only) stored in another string but the error occured.
error is: "to not use > in string"(little bit i forget the error message).


Answers (5)