DateTime Format Problem with Turkish Locale dd.MM.yyyy

Share the info
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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:

1-)

DateTimeFormatInfo dtfi = new DateTimeFormatInfo();

dtfi.ShortDatePattern = “dd.MM.yyyy”;

dtfi.DateSeparator = “.”;

DateTime date = Convert.ToDateTime(“13.01.2013″, dtfi);

2-)

IFormatProvider theCultureInfo = new System.Globalization.CultureInfo(“tr-TR”, true);

DateTime date;
date = DateTime.ParseExact(“13.01.2013″, “dd.MM.yyyy”, theCultureInfo);
Non of the methods above seem to be working, and most of the samples on the internet were coming down to these 2.

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:)

Shortestlink for this post: http://s.tl/baL

Hope this helps someone.

Good luck,
Serdar.


Share the info
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
serdar-o

serdar-o

Systems Engineering Team Lead at AtoS
I am a Senior Software Engineer/ Senior Systems Engineer. I have BS degree on Electrical and Electronics Engineering and MS degree on Software Engineering. I have worked as Test Engineer, Software Engineer, Systems Engineer, Development Team Lead and Project Manager thru various defense projects. Currently I am working as Senior Systems Engineer in a Big European IT Company. During these professional experiences of mine I learned a lot about quality management, risk management, configuration management, software development life cycles and many more which helped me gain a broad range of interdisciplinary knowledge. Other than that professional path that I get paid for I love coding web stuff, learning/applying new technologies and techniques to create things on the internet since 2004.
serdar-o

@serdarosmanonur

h='Hello';hw=(function(w1){return function(w2){alert(w1+w2);}})(h);hw(' World');
RT @Flippa: @SerdarOsmanOnur Thanks! We like it too :) - 1 day ago
serdar-o
serdar-o
Pin It
Add Comment Register



Leave a Reply

Login with your Social ID

Your email address will not be published. Required fields are marked *


two + 6 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>