How to sort a data table based on a column which is a date

How to sort a data table based on a column which is a date

Hi @maria.josephina

See this

Thanks,
Prankur

Hi @PrankurJoshi

THankyou
datatable dt = (From row In dt2.Select Order By Convert.ToInt32(row("Column1")) Select row).ToArray.CopyToDatatable()

This worked.
But how to specify the order type (ASC or DESC)

Use this for desc

datatable dt = (From row In dt2.Select Order By Convert.ToInt32(row("Column1")) Descending Select row).ToArray.CopyToDatatable()

Thankyou somuch.
I have created the below statement for Sorting based on Datetime.

This is not working :
(From row In filteredSchemaDT.Select Order By DateTime.ParseExact(row(“RECEIPTDATE”), “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture) Descending Select row).ToArray.CopyToDatatable()

2 Likes

try this

(From row In filteredSchemaDT Order By DateTime.ParseExact(row.Item("RECEIPTDATE").ToString, "dd/MM/yyyy", 
System.Globalization.CultureInfo.InvariantCulture) Descending Select row).CopyToDataTable

Thanks,
Prankur

4 Likes

Worked well. Thank you so much for helping out :slight_smile:

1 Like

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