View Single Post
  #6 (permalink)  
Old September 3rd, 2009, 10:58 AM
skhan skhan is offline
Authorized User
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts

I am trying to format the date as follows:

foreach (DataRow r in ds.Tables[0].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();
         NotesLabel.Text= date3;

       //DateTime dt = Convert.ToDateTime(r["First_Resurvey_Date"]);
       //string format = "dd/MM/yy";
       //String date;
       //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.