CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    Melbourne, Australia
    Posts
    44

    sorting a date field in the list?

    I have a list, that displays there columns,one of them is a date field and when I go into properties I can assign sorting properties for each of those column,so that is what I have done.

    But the product of the date field sort is that the field is sorted like (1 apr 1999, 1 apr 2000) so it really sorts by the first digit, insted of looking at the date as a whole.

    i am not aware if we can do anything to get this to sort the way I need it, and if not how would you do it and can it be done, I am sure it can.

    Thanks

  2. #2
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    Re: sorting a date field in the list?

    i haven't done this in VB, but to get around it in another language (Jade) I create an invisible column that stores the date in a format that can be sorted on. then when someone clicks the column to sort on the displayed field, you redirect the sort and tell it to use the hidden field instead.

    Hope that helps - like I say, I've never done it in VB

  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: sorting a date field in the list?

    That is indeed the way to do that in VB.
    In order to be able to sort on a date correctly, you will need to store it in the form YYYYMMDD.
    Tom Cannaerts
    email: cakkie@cakkie.be.remove.this.bit
    www.tom.be (dutch site)

  4. #4
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: sorting a date field in the list?

    As stated by Cakkie, the best way is to have the dates reformatted first into a specific string format YYYYMMDD. But it will depend also on how you sort the field, if you want to use the ADO recordset object you can store the date directly into a DATE field, and from there sort the records by setting the Sort property with the field name, and finally retrieve the sorted records by looping the recordset into your list.
    Busy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured