I'm hoping that there is something I am not seeing clearly, but to simplify, I have the below code
foreach (DataRow row in dt.Rows)
{
row["StartOn"] = Convert.ToDateTime(row["StartOn"].ToString()).ToString("MMM dd").ToString();
}
If I run the below code I get “Aug 09”
Convert.ToDateTime(row["StartOn"].ToString()).ToString("MMM dd").ToString();
If I look to see what is in row[“StartOn”] after this change it contains “8/9/2016 12:00:00 AM”
I'm unable to format my DataRow to an "MMM dd" format
What is
dt.Columns["StartOn"]
. I suspect this isDateTime
. Let me break down your single line of code into 2 lines.In line 1, you are converting a
DateTime
object to a string object. But on line 2, you are implicitly converting yourstring
to aDateTime
BTW, you can use the below line to do the conversion
StartOn is apparently a DateTime type. DateTime types do NOT have a format. They are an object that specifies year, month, date, and time (among other things). All you are doing in your conversions is stripping out the time so that the new datetime has a time of 12:00 am.