Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2715
Sorting a date column with string values
posted

Hi!

I'm populating a grid with data from a oracle database, like this : 

"select name, to_char(date,'DD-MON-YYYY HH24:MI:SS') from atable".

So when using the sort functionality in the grid, the values are sorted by their string value not their actual date value. But i don't like this, and i would like to still have the date formated but when sorted to be sorted as a datetime column. How do you recomment i should do this ?

Thank you!

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    The best thing to do is.. don't use strings for dates. Doing so will cause problems in a number of areas like sorting, filtering, and calculations.You would be better off getting the dates as DateTime structures and then applying formatting in the UI. The grid column has a Format property which you could use to display the dates in the format you want without converting them to strings.

    But, if for some reason, you cannot do that, then the alternative would be to write a SortComparer for the column that converts the strings into dates and compares them.

     

Children