I am trying to format the date as follows:
foreach (DataRow r in ds.Tables.Rows)
string date1= r["First_Resurvey_Date"].ToString(); //works fine
string date2= r["Last_Resurvey_Date"].ToString(); //works fine
resultsLabel.Text = date1+" "+date2; //works fine
//string dateString = r["First_Resurvey_Date"].ToString(); // Modified from MSDN [This doesn't work as sais invalid date]
string format = "dd-MMM-yy";
DateTime dateTime = DateTime.ParseExact("3/14/1985 12:00:00 AM", format, CultureInfo.InvariantCulture); [So, I have tried putting the data displayed as a string, but this doesn't work either]
string date3= dateTime.ToString();
//DateTime dt = Convert.ToDateTime(r["First_Resurvey_Date"]);
//string format = "dd/MM/yy";
//date = dt.ToString(format,DateTimeFormatInfo.InvariantInfo);
It says, "Exception: String was not recognized as a valid DateTime. "
My dates are currently displayed as "3/14/1985 12:00:00 AM", but I would like to have it as "14-Mar-85" or even "3/14/1985" would do as well.
Thanks in advance.