How to sort date column

Hi ,

Am extracting date values into data table called ‘build_dt’ and i wanted to sort the datatable date values. Below are the values fetched after screen scraping into ‘build_dt’ (excel) .

Please let me know how to sort the dates so that the old date should be placed first and the latest one should be at last.
I tried with ‘Sort Data Table’ but it is not satisfying my requirement or am doing it wrong. Let me know how can I achieve it
Thanks in advance

01/05/2021
12/03/2020
12/03/2020
12/03/2020
12/03/2020
12/03/2020
12/03/2020
12/03/2020
12/03/2020
12/31/2020
12/31/2020
12/31/2020
12/31/2020
12/31/2020
12/31/2020
01/04/2021
01/05/2021
01/06/2021

1 Like

@Vinutha_L - Please try like this…

(From r In DT Order By DateTime.ParseExact(r.Item(“YourColumnName”).ToString, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture) Descending Select r).CopyToDataTable

2 Likes

Hi @Vinutha_L ,

Please find the solution below:

DtRaw.AsEnumerable.OrderBy(Function(d) CDate(d.Item(“Date”).ToString.Trim)).CopyToDataTable

Note: If you use OrderBy, it will order your dates in Ascending by default, and if you use OrderByDescending, it will do so in Descending order.

1 Like

Hi @prasath17

Thank you so much…it worked!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.