Sunday 19 June 2016

How to change datetime format for windows server?

Why this question, because earlier my web application was hosted in other server which was giving date time in format "6/17/2016 1:30 PM" from application. Where as once hosted on another server it was giving "17-06-2016 1:30 PM". Due to this our application was throwing Input string was not in a correct format.

I tried every thing like
parse and parse exact

var format = "MM/dd/yyyy hh:mm:ss tt ffff";
DateTime latwriteat = DateTime.ParseExact(fdata[1].ToString(), format, CultureInfo.InvariantCulture);

Change the datetime format of your server from:
Control Panel -> Regional and Language Options -> Advanced

Open IIS and follow below steps: (For IIS7)
- Click on you Website
- Select .NET GLOBALIZATION option
- From Culture tab, select required Culture and UI Culture.
- Finally iisreset.
- Dones....

But finally i got solution through registry edit
Navigate to the HKEY_USERS\Default User\Control Panel\International registry subkey. Double-click the sShortDate registry entry. Set the value to the date format required (e.g., dd/MM/yyyy), then click OK. You can also change the sLongDate registry entry for the longer date format (e.g., dd MMMM yyyy), then click OK

This solution is applicable for all windows server like 2008, 2012.