Results 1 to 5 of 5

Thread: Date sort problem

  1. #1

    Thread Starter
    Fanatic Member spud's Avatar
    Join Date
    Aug 2000
    Location
    Munster (Germany)
    Posts
    542

    Unhappy Date sort problem

    I am using the following to search an database:

    Private Sub Command1_Click()
    Data1.RecordSource = "SELECT * FROM dates WHERE Date BETWEEN #" & Text1.Text & "# AND #" & Text2.Text & "#;"
    Data1.Refresh
    End Sub

    Private Sub Command2_Click()
    Data1.RecordSource = "SELECT * FROM dates order by year(Date), month(Date), day(Date)"
    Data1.Refresh
    End Sub

    the problem is that after the search between two dates is completed the dates are not in order, hense Command2. However this refreshies the current search and lists all the dates in the database

    If I try it the other way its the same result


    Any help?
    Haven't got anything to say that is the least bit interesting.
    www.tartan-underground.com

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Try using the FORMAT() function for the sort:

    Code:
    ORDER BY FORMAT(DateField, 'yyyy mm dd')
    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    Fanatic Member spud's Avatar
    Join Date
    Aug 2000
    Location
    Munster (Germany)
    Posts
    542

    Unhappy Sorry....

    I dont know this command

    where does it go in the grand scheam of things?

    Thxs
    Haven't got anything to say that is the least bit interesting.
    www.tartan-underground.com

  4. #4
    Lively Member
    Join Date
    Jun 2002
    Location
    Kuwait
    Posts
    85
    Private Sub Command1_Click()
    Data1.RecordSource = "SELECT * FROM dates WHERE Date BETWEEN #" & Text1.Text & "# AND #" & Text2.Text & "# order by date "
    Data1.Refresh
    End Sub

    this gives the dates between two dates in an order.

    Data1.RecordSource = "SELECT * FROM dates order by year(Date), month(Date), day(Date)"

    In this inspite of
    year(Date), month(Date), day(Date) you can just use order by Date . It also gives the same result you want.
    Your attitude determines your altitude!!!

  5. #5

    Thread Starter
    Fanatic Member spud's Avatar
    Join Date
    Aug 2000
    Location
    Munster (Germany)
    Posts
    542

    Wink Thx

    This works great, it also reduced my code by a page! thx again
    Haven't got anything to say that is the least bit interesting.
    www.tartan-underground.com

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