I want to sort a column in Excel which has datetime value. I used read range. Got the excel data into datatable and than used sort datatable activity The table got sorted in the way i want but the datetime format got changed from 12 hour to 24 hour format. Need the datetime column in same format as it was at the start.
Before sorting the DataTable, create a new column to store the formatted datetime values in the desired format. You can use the Add Data Column activity to add a new column of type String to the DataTable. Iterate through each row in the DataTable using a For Each Row activity. Inside the loop, use the Assign activity to assign the formatted datetime value to the new column.
You can use the ToString method with a specific format string to achieve the desired format. For example, if you want to convert a datetime value to a 12-hour format with AM/PM indicator, you can use the following expression:
Replace “NewColumn” with the name of the new column you added and “DateTimeColumn” with the name of the datetime column in the DataTable.
After assigning the formatted datetime values to the new column, use the Sort Data Table activity to sort the DataTable based on the new column. Make sure to select the correct sorting order (ascending or descending) and choose the new column as the sorting key.