i have datatable with multiple datetime columns now the datetime is formatted as dd/MM/yyyy hh:mm:ss tt which is giving me output 01/01/2016 10:00:00 AM i want to format that to dd/MMM/yyyy hh:mm:ss tt, expected output 01/Jan/2016 10:00:00 AM.
I tried this but it is not doing the conversion.
my datatable has values
timestamp
06/01/2016 1:32 PM
06/01/2016 3:33 AM
07/01/2016 4:42 AM
string query = "SELECT t1.[timestamp] FROM [REPORT] t1";
//I should not change this because i am not supposed to give alias name to column as per requirement
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = new DataTable();
dt=ds.Tables[0];
//dt REsult is
//2016-01-06 03:33:27.810
//2016-01-06 03:33:27.810
// expected result is
//2016/Jan/06 03:33:27.810
//2016/Jan/06 03:33:27.810
foreach (DataColumn dcol in dt.Columns)
{
if (dcol.DataType == typeof(DateTime))
{
dt.Columns[dcol.ColumnName].Convert(val => DateTime.Parse(val.ToString()).ToString("dd/MMM/yyyy"));
}
}
dataGridView1.DataSource = dt;
dataGridView1.BindingContext = new BindingContext();
}