I want to convert string date to system datetime in C#. The user enters date through textbox and it should be converted as to datetime. I trid following code but its not working…
DateTime ToDate = Convert.ToDateTime(txtToDate.Text);
DateTime FromDate = DateTime.Parse(txtFromDate.Text);
It shows the following exception
“String was not recognized as a valid DateTime.”
How to do this…???
You could use
DateTime.ParseExact(). That way you can specify the format of the input string, so it will be parsed correctly, for example: