Sort datatable ascending

Have a datatable with column created date all dates in table are in string format, req is to sort the table with created date in ascending order.oldest created date shall be at top!
Tia

Hi,

If your date format is like “MM/dd/yyyy” style for example, the following will work.

dt = dt.AsEnumerable.OrderBy(Function(r) DateTime.Parse(r("DateColumn").ToString)).CopyToDataTable()

If it throws Invalid string exception, we need to use ParseExact method.

Regards,

Can we update data type of a column created date to datetime at a shot?

Hi,

Do you mean to want to change column data type from String to DateTime? If so,ee need to create new DateTime type column then convert and set all the data to it. ( and remove old column if necessary)

Regards,

Yeah