Home Website date format changes after uploading even though cultures are set globally
Reply: 0

Website date format changes after uploading even though cultures are set globally

user1687
1#
user1687 Published in June 23, 2018, 8:00 am

I have created a form that uses a bootstrap datepicker to allow the user to input the date, and the methods used work perfectly when testing on my localhost. A problem occurred when i uploaded the site to do a final test which switches the date format throughout my site from dd/MM/yyyy to dd-MM-yyyy even though i have converted the date using global.asax culture settings. This date format wouldn't be such an issue but my forms no longer submit and the error i get says "sequence contains no elements" I have checked all settings on both the server and in the site that could be causing this but cannot seem to fix the issue. Thanks in advance for any suggestions.

Convert the date to the specified format on the front end:

.GetValueOrDefault().ToString("dd/MM/yyyy")

Global.asax code:

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    CultureInfo newCulture = new CultureInfo("en-ZA");
    newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
    newCulture.DateTimeFormat.DateSeparator = "/";
    Thread.CurrentThread.CurrentCulture = newCulture;
    Thread.CurrentThread.CurrentUICulture = newCulture;
}

Controller Code:

_vehicle[c] = new Vehicle()
{
    inceptionDate = string.IsNullOrEmpty(frm["inception_" + c]) ? 
    (IsFleetClient ? DateTime.Now.Date.AddDays(1) : DateTime.Now.Date) : 
    Convert.ToDateTime(frm["inception_" + c]).ToLocalTime()
};
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.320406 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO