Converting a common SQL time format to C # (all options)?

If I have theses about valid sql dates in C # lines:

(each date may be in a different order inside), for example:

01 feb 2010
feb 01 2010
2010 01 feb
...
...

I want to convert the date of a string to DateTime(C #). (I want the ability to convert each format from the list above)

while parsing requires a combination 3!, is there a better solution?

+5
source share
1 answer

I think I got ... enter image description here

string[] str = new[] { "01 feb 2010","feb 01 2010","2010 01 feb","2010 feb 01","feb 2010 01" };
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");                       
for (int i = 0; i < str.Length; i++)
{
    DateTime t = DateTime.Parse(str[i], culture);
    t.Dump();
}
+2
source

All Articles