1

I have the following function

DateTime fromDateParam = DateTime.ParseExact(Convert.ToString(DateTime.MinValue),"dd.MM.yyyy HH:mm:ss",null);

It says input string not recognised as a valid date.

Any ideas how I can get any the min date recognised to parse exact?

JL.
  • 75,548
  • 121
  • 304
  • 451

2 Answers2

4

Well you're converting the original time to a string using the default formatting, but then you're specifying custom formatting for the parsing.

If you specify a format string using DateTime.ToString(format) and keep the format consistent, it works fine:

string formatString = "dd.MM.yyyy HH:mm:ss";
string text = DateTime.MinValue.ToString(formatString);
Console.WriteLine(text);
DateTime fromDateParam = DateTime.ParseExact(text, formatString, null);
Jon Skeet
  • 1,335,956
  • 823
  • 8,931
  • 9,049
1

In other words (continuing Skeet's answer), Convert.ToString(DateTime.MinValue) is based on current/default CultureInfo, etc.

Ron Klein
  • 8,900
  • 9
  • 52
  • 87