String was not recognized as valid Date Time

Here I am getting the from date from UI and passing it to API. API accepts "yyyy-MM-dd" format. Here I have writtem some piece of code but its giving me some exception like "String was not recognized as valid Date Time".Please help me how to solve this exception
fromDate.Text = e1.Date.ToShortDateString();
DateTime sourceDate = DateTime.ParseExact(fromDate.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
fromDate.Text = sourceDate.ToString("yyyy-MM-dd");

Thanks in Advance


Best Answer


Sign In or Register to comment.