Skip to content

Datetime format value of a column of a datarow

Sairam Soham

Asked Jun 3, 2015, 6:03 AM EDT1 answer
Share
LinkedInX

In the following for loop row[0].ToString has datetimme value

 foreach (DataRow row in ds.Tables[0].Rows)
            {
               

                   dt.Rows.Add("8W2_Mtr_EndPoint",
                    "EndPointChannelID",
                    "Electric",
                    row[0].ToString()
                   
            
            } //foreach


I want to format this value in the format "yyyy-MM-dd HH:mm".

I tried the following

 row[0].ToString("yyyy-MM-dd HH:mm")

Am I missing something?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    My problem is solved.
     
    I used the following syntax and it worked.

     ((DateTime)row[0]).ToString("yyyy-MM-dd HH:mm")

    0