Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:09:48+00:00 2026-05-30T05:09:48+00:00

I have an array of dates whose format is like this: 10/15/2005 or 2/10/2011.

  • 0

I have an array of dates whose format is like this: 10/15/2005 or 2/10/2011.

Let’s say the array has 10 dates, some of which may be duplicates.

arrDates(9) ‘elements 0-9 represent 1 date

What is the best way to re-arrange the elements so that they are in chronological order?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:09:50+00:00Added an answer on May 30, 2026 at 5:09 am

    For short lists (arrays) you could use an invisible ListBox, or a fabricated ADO Recordset, or you could hand-code a short sort routine. Performance usually isn’t a big issue until you have larger lists to sort.

    Here is an example using a temporary Collection. It has a similar advantage to that of using a Recordset in that it can carry multivalued items, something that gets clunky fast using multidimensional arrays. To do that with a Collection you’d create a small Class containing the values (including the sort key) you need to carry along.

    This particular approach could be optimized by using a binary search in place of the simple sequential search (the “J loop” here):

    Option Explicit
    
    Private Sub Form_Load()
        Dim A(9) As String, B(9) As String
        Dim I As Integer, J As Integer
    
        'Create some data, here we'll use String values but Date,
        'Integer, Double, whatever work as well.
        Randomize
        For I = 0 To 9
            A(I) = CStr(Fix(Rnd() * 100000))
            A(I) = Right$(String$(5, "0") & A(I), 6)
        Next
    
        'Sort A() as B().  Could just as easily copy the results
        'back into A() instead.
        With New Collection
            For I = 0 To UBound(A)
                For J = 1 To .Count
                    If A(I) <= .Item(J) Then
                        .Add A(I), , J
                        Exit For
                    End If
                Next
                If J > .Count Then .Add A(I)
            Next
    
            For I = 1 To .Count
                B(I - 1) = .Item(I)
            Next
        End With
    
        'Print before and after.
        AutoRedraw = True
        Print "A", "B"
        Print
        For I = 0 To 9
            Print A(I), B(I)
        Next
    End Sub
    

    Of course with something like a “date” represented as a String value you’d still need to normalize it for sorting as others have mentioned. Here that is simulated by creating String values based on numbers and padding with leading zeros for normalization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array with dates as indices which I'm plotting. I'd like to
I have an array of dates which are in the format 20100808 (YYYYMMD). How
I have a multidimensional array which, when echoed in PHP, looks like this: {
I have some code which builds an array of date ranges. I then call
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
Let's say I have array of bytes: byte[] arr = new byte[] { 0,
I have an array of dates in ISO8601 format and need to sort them.
I have an array of dates e.g. Fri Jan 28 10:13:19 UTC 2011 Thu
Okay, so I have this array. Currently it pulls multiple payment amounts and dates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.