how to find the greatest date in a arry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandru8
    New Member
    • Sep 2007
    • 145

    how to find the greatest date in a arry

    hi to all
    iam having dates in array (dd/mm/yy)
    i need to find the greatest date value from the array
    ex
    array(1) = 01/01/2003
    array(2) = 01/03/2003
    array(3) = 01/05/2003
    array(4) = 02/02/2004
    array(5) = 01/01/2003
    array(6) = 03/04/2008


    the highest value is 03/04/2008


    can any one help me
    its vvvery urgent
    please
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    sure

    make the array a DATE array, then you can use (depending on the version) a math.max() function, or create it by yourself, e.g.

    [CODE=vb]dim arr1(1 to 10) as date
    'here's the code where you fill the dates into the array
    dim i as integer
    dim tmp1 as date

    tmp1=arr1(1)
    for i = 2 to 10
    if arr1(i) > tmp1 then tmp1=arr1(i)
    next
    msgbox tmp1[/CODE]

    HTH

    Comment

    • junkieman
      New Member
      • Jun 2008
      • 1

      #3
      if youre using proper date objects, try sorting ascending, and the last item is your highest:

      Code:
      ' sort the date array
      Array.Sort(dates)
      
      ' your highest date will be:
      dates(dates.GetUpperBound(0))
      
      ' your lowest date will be:
      dates(0)

      Comment

      Working...