Have to sort a data table based on date time column which is in the format yyyy-mm-dd hh:mm:ss
Also time appears as a next line in the same column. Any solution please
I have used the below code but its not working. Without time
(From row In dtResult Order By DateTime.ParseExact(row.Item(“Column control menuUpdatedSort”).ToString, “yyyy-mm-dd hh:mm:ss”,
System.Globalization.CultureInfo.InvariantCulture) Descending Select row).CopyToDataTable
(From row In dtResult Order By DateTime.ParseExact(row.Item(“Column control menuUpdatedSort”).ToString, (“yyyy-MM-dd HH:mm:ss”),
System.Globalization.CultureInfo.InvariantCulture) Descending Select row).CopyToDataTable
hi @ teenu
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
I tried the same code
(From row In dtResult Order By DateTime.ParseExact(row.Item(“Column control menuUpdatedSort”).ToString, “yyyy-MM-dd HH:mm:ss”,
System.Globalization.CultureInfo.InvariantCulture) Descending Select row).CopyToDataTable
It gives me error “String was not recognized as a valid DateTime”
(From p In dataTable Order By DateTime.ParseExact(p.Item(“Date”).ToString.SubString(0,10), “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture) Ascending Select p).CopyToDataTable… It worked for me.
Still it gives me error “String was not recognized as a valid DateTime”
(From row In dtResult Order By DateTime.ParseExact(row.Item(“Column control menuUpdatedSort”).ToString.SubString(0,10), “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture) Ascending Select row).CopyToDataTable
where “Column control menuUpdatedSort” is the column name where the date has to be extracted which is of string data type