Click here to Skip to main content
15,887,256 members
Please Sign up or sign in to vote.
4.11/5 (3 votes)
See more:
Our Old website was in VS 2008 .It works fine for framework 3.5 for datetime.
Now we converted our site to VS 2010.From this onward we got datetime problem for calender extender with dd/MM/yyyy format using compare validator. We set code in Global.asax as

C#
protected void Application_BeginRequest(object sender, EventArgs e)
   {
      //var customCulture = new System.Globalization.CultureInfo("en-GB");
       HttpContext.Current.Response.AddHeader("x-frame-options", "DENY");

       // Code that runs on application startup
       CultureInfo newCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
       newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
       newCulture.DateTimeFormat.DateSeparator = "/";
       Thread.CurrentThread.CurrentCulture = newCulture;
       //System.Threading.Thread.CurrentThread.CurrentUICulture = customCulture;
   }

This works Fine for VS 2008 but after converting to VS 2010 Compare Validator gives error for calendor extendor which is having 'dd/MM/yyyy' format.
For this we tried
1. We tried To add
<globalization culture="”en-GB”/"> in Web.Config in System.web But it doesn't work.
2. Then We tried to add
C#
var customCulture = new System.Globalization.CultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentUICulture = customCulture;

in Global.asax
But this also didn't work.

1. Whether this belongs to local Server.
2. We don't want to change calender extender format as 'MM/dd/yyyy' as this change has to be in all project.
3. How to fix problem in Global.asax or web.config.Please help us urgently as we trying for 4 Days .Thanks in advance.....
Posted
Updated 24-Oct-14 0:47am
v2
Comments

 
Share this answer
 
Comments
Richard MacCutchan 24-Oct-14 6:56am    
Please do not go round editing old questions; it just moves them to the top of the queue and adds clutter to the forums. As I said earlier, please use your new found privilege with care, and common sense.
[no name] 24-Oct-14 7:12am    
ok sorry for the mistake i have done. I won't repeat it. thanks a lot.
get your system date format and convert realted to it :

C#
char sysseparator = Convert.ToChar(CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator);
string date=CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToString();
                 string date1 = '12-12-2013';//your date here
                 date1 = date1.Replace(&#39;-&#39;, sysseparator);
                 string[] splt = date1.ToLower().Trim().Split(sysseparator);
                 date = RemoveDuplicateChars(date.ToLower(), sysseparator.ToString());
             date = date.Replace("d", splt[2].PadLeft(2, '0'));
    date = date.Replace("m", splt[1].PadLeft(2, '0'));
                        date = date.Replace("y", splt[0]);
 
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