How to convert “dd/mm/yyyy” to “yyyy-mm-dd” format.
I’ve tried it like this:
DateTime dtInputDate = DateTime.Parse(txtDate.Text); //txtDate.Text = "19/07/2012"
string strOutputDateFormat = "YYYY-MM-DD";
dtInputDate.ToString(strOutputDateFormat);
txtDate.Text = dtInputDate.ToShortDateString();
but got an error:
String was not recognized as a valid DateTime.
You may use Parse Exact, and specify the format, as
"d/M/yyyy"Edit: Here replace
strDatewithtxtDate.Textfor your code