I have a datatable which I extract from a SAP table. I’ve created a simplified datatable which contains similar data to what I’m going to be working with:
The data is extracted from SAP as stringss
My question is this, how can I change the format of the ‘Start’ column to be datetime after the data has been extracted from SAP into the datatable? I’m needing to convert the whole column to DataTime as I’m going to need to perform some date calculations on data contained in the ‘Start’ Column.
I’ve tried using BalaReva’s EasyDataTable activity 'DateTime ParseTo DataTable, however it put data in the incorrect format (yyyy-MM-dd) and I must have data in the dd.MM.yyyy format.
Assuming the column changed to type DateTime yyyy-MM-dd is only representation of DateTime value, if you later want write the date in other format, use this row(“Start”).ToString(“dd.MM.yyyy”)
Thanks, I understand what you mean by thats the way that the datetime value is stored and that the format can be changed on output, however when I try this is the error I’m getting:
If you try to change the column type directly, there is a chance you might run into a collection modified error, which is why its best to create a separate DataTable and perform the conversion.
(From row In dt_sampleData.AsEnumerable()
Let dte = DateTime.ParseExact(row("Start").ToString.Trim,"dd.MM.yyyy",System.Globalization.CultureInfo.InvariantCulture)
Let ra = New Object(){dte,row(1)}
Select dt_result.Rows.Add(ra)).CopyToDataTable()