Task: Get a Date string and convert it to DateTime object in the form of “dd.MM.yyyy”.
Problem: No matter what you do, you can not change the default yyyy/dd/MM (or yyyy/MM/dd) format.
Yes, this was my case while I was trying to convert the format of Date value, and then record that value into my database. I wanted to have my date values in “dd.MM.yyyy” format in the database. Is it too much to ask? Anyway let's get going…
Methods I tried:
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.ShortDatePattern = “dd.MM.yyyy”;
dtfi.DateSeparator = “.”;
DateTime date = Convert.ToDateTime(“13.01.2013”, dtfi);
IFormatProvider theCultureInfo = new System.Globalization.CultureInfo(“tr-TR”, true);
Then I found out that I had not set the “culture” info on web.config file. So I added uiCulture=”tr-TR” culture=”tr-TR” values into <globalization /> tag and boom! it was done:)
Hope this helps someone.