Use DateTime.Parse and know the regional settings. You can get around regional settings by providing your own CultureInfo. I do not know which language you are using, but my language (Danish) supports the date format (dd.mm.yyyy). Thus, I use the following syntax:
string inputDate = "31.12.2001";
CultureInfo cultureInfo = new CultureInfo("da-DK");
DateTime parsedDate = DateTime.Parse(inputDate, cultureInfo);
Alternatively, you can split the input line and build a new date.
Regards, Morten
source
share