hey guys i’m trying to sort an excel file base on a column which are dates like this
i’m using (From row In dtFilter Order By DateTime.ParseExact(row.Item(“Database date”).ToString, “dd MMMM yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture) Ascending Select row).CopyToDataTable
i always get error when i sort it saying “string was not recognized as datetime”. i suspected it was because of the date format, so i changed all the format in the excel to dd/MM/yyyy HH:mm:ss manually(which is a lot of work) and try again with that format, and it worked perfectly.
anyone knows what date format shoud i use ? or is there another solution ?
Thank you
Buddy your format is correct…May the string might have some issue, Lets check whether any space is there after the date in your column
(From row In dtFilter Order By DateTime.ParseExact(row.Item(“Database date”).ToString.Trim, “dd MMMM yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture) Ascending Select row).CopyToDataTable
hi @Sreelatha278,
it didn’t work tho, is there anything wrong with this ?
(From row In dt Order By DateTime.ParseExact(row.Item(“Database date”).ToString, “dd MMMM yyyy HH:mm:ss”, new System.Globalization.CultureInfo(“id-ID”)) Ascending Select row).CopyToDataTable
i also tried this
dt.AsEnumerable.OrderBy(Function(d) DateTime.ParseExact(d(“Database date”).ToString,“dd MMMM yyyy HH:mm:ss”,new System.Globalization.CultureInfo(“id-ID”))).CopyToDataTable