Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what is proper Date format in mvc3
i am getting error
while selecting date as invalid date
and have set date format


C#
protected void Application_BeginRequest()
       {

           System.Globalization.CultureInfo newCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
           newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
           newCulture.DateTimeFormat.DateSeparator = "/";
           System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;
       }
Posted
Comments
Maciej Los 11-Apr-14 12:42pm    
I think your question has nothing to do with code provided in a question.
As far i can see, you're trying to change date format, but you did not explain why! Remember date is a date no matter of displayed format!
Member-515487 11-Apr-14 13:55pm    
Actually my problem is that then I select any date from jquery date picker in dd/mm/yy mvc client side validn get call and get error as incorrect date textbox get red background

1 solution

JavaScript
$.validator.addMethod('date',
  function (value, element, params) {
      if (this.optional(element)) {
          return true;
      }

      var ok = true;
      try {

          $.datepicker.parseDate('dd/mm/yy', value);
      }
      catch (err) {
          ok = false;
      }
      return ok;
  });


This Works
 
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