I have a data table with 4 columns datetime,id, message & status. I want to update the datetime column with a new datetime (updated datetime is in different time zone, from CST to UTC). First I was thinking to do it like I would take the datetime column and store it in a list and convert the list to utc time zone from cst.Then add the list to the same table and rearrange the columns. But this sounds stupid so is there any way to update the existing value with new values for one column of datatable.
I found the below code in one of the posts but not sure what exactly is happening.
var rowsToUpdate =
dt.AsEnumerable().Where(r => r.Field<string>("datetime") == datetime);
foreach(var row in rowsToUpdate)
{
row.SetField("datetime", utcDate);
}
The data in datatable is in CST timezone but I want that timezone to be converted to UTC timezone and update the table.
List<DateTime> lstCST = new List<DateTime>();
lstCST = datatable.AsEnumerable().Select(r=>r.Field<DateTime>("CSTDatetime")).ToList();
List<DateTime> lstUTC = new List<DateTime>();
DateTime dt = DateTime.Now;
foreach(var v in lstCST )
{
dt= TimeZoneInfo.ConvertTimeToUtc(v);
lstUTC.Add(dt);
}
Can anybody point me in the right direction on how to do this.