Please enable Javascript for better experience...
Datetime format is getting changed on production environment
By Rahul Kumar Jha | Oct 11, 2015 | In Tips | Total Views [ 4075 ]
Taged In
(0 Like)

Set culture, UI culture in <Globalization /> section in web.config file to work on same datetime format both on local as well as production environment.

The Problem

I was setting my bootstrap calendar to get datetime in "dd/mm/yyyy" format. It was working fine on my local machine. Format was showing correctly and I was able to search records as it should be. But as I moved to production environment, it started creating problem. First of all if I was taking date as say "20th Oct, 2015", it was throwing datetime conversion error (Out of bound). I debugged my code and found that Datetime was not in correct format.

The Solution

First of all let's see the code. I had created a MVC application. Below is my jquery code which is calling my MVC action.

JQuery code

function SearchBox() {
var f = $("#fromDate").val();
var t = $("#toDate").val();
type: 'POST',
url: "/Home/Search/",
data: { fromDate:f, toDate:t },
success: function (result) {
error: function (ex) {
alert('Facing error while processing your request. Please try later.' + ex)

Action Method()

public JsonResult Search(DateTime fromDate, DateTime toDate)
var model = search.SearchResult(fromDate, toDate);
return Json(new { Data = model}, JsonRequestBehavior.AllowGet);

DateTime parameter was not converting date correctly.

The problem was with application culture. Set culture info in web.config file in section and you are done.

To make it working, I simply added section in my web.config file.

Globalization section

uiCulture="en-GB" />


It was a small trick or say mistake. Hope it should you.

Share this

About the Author

Rahul Kumar Jha
Rahul Kumar Jha
Founder, Developer

Public profile: user/profile/99900001

Has working experience in different phases of Software Development Life Cycle (SDLC) in CMS, Gaming, Health Care and Financial Services domain using Agile pattern. Working experience in Design patterns, ASP.NET, MVC, ANGULAR, ANGULAR JS, Windows application, WCF, ADO.NET, SQL Server and Test Driven Development (TDD) environment with JQuery, JavaScript, N-Unit, Entity Frameworks, LINQ, Code Refactoring and Business Objects Models.

User's Comments

Please SignUp/Login to comment...

Or comment as anonymous...
* Name
* Email ID