Hmmm...
In few words: string representation of
DateTime
data type depends on localization.
Please see:
Design and Implementation Guidelines for Web Clients[
^]
How to: Display Localized Date and Time Information to Web Users[
^]
Formatting Date and Time for a Specific Culture[
^]
I'd suggest to use extension method to "convert" string into DateTime using specific localization:
public static class DateExtensionMethods
{
public static DateTime StrToDate(string strDate)
{
System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
DateTime dt;
return DateTime.TryParse(strDate, culture, System.Globalization.DateTimeStyles.None, out dt) ? dt : new DateTime(1899,12,31);
}
}
Usage:
void Main()
{
List<string> stringDates = new List<string>()
{"20/10/2015",
"10/20/2015",
"2013/10/20",
"10/20/2014",
"2015/10/20",
"2015/20/10"};
var result = stringDates.Select(d=>DateExtensionMethods.StrToDate(d));
}
Result:
1899-12-31 00:00:00
2015-10-20 00:00:00
2013-10-20 00:00:00
2014-10-20 00:00:00
2015-10-20 00:00:00
1899-12-31 00:00:00
Final remark:
you should work on data, not on its string representation!