I have a DataTable with 8 Columns and a large number of Rows. The fact is that each cell has stored dates like this: “MM/dd/yyyy HH:mm:ss” and I want it in this format: “yyyyMMdd”.
I have tried with For each but there are many rows to iterate and it is not convenient, so I know that there are LINQ queries that facilitate this change of format for each column. I would like to know what it would be and how it would be implemented. Best regards
I create this statement with what your post says and in theory it doesn’t give me any syntax problem but it returns this error:
System.ArgumentException: The input array is longer than the number of columns in this table.
The statement is this:
dtNew = (From d In dt.AsEnumerable Let gp = d.Field(Of DateTime)(“Column1”).ToString(“yyyyMMdd”) Let ra = d.ItemArray.Append(gp).ToArray Select dtNew.Rows.Add(ra)).CopyToDataTable
But of course, I don’t do anything like Array, I need to place it inside the DataTable. So here is the problem, I need each column to have the format I need