Connecting Tech Pros Worldwide Help | Site Map

how to find the greatest date in a arry

chandru8's Avatar
Familiar Sight
 
Join Date: Sep 2007
Posts: 145
#1: Jun 24 '08
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's Avatar
Expert
 
Join Date: Apr 2007
Location: Mexico City
Posts: 1,155
#2: Jun 24 '08

re: how to find the greatest date in a arry


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.

Expand|Select|Wrap|Line Numbers
  1. dim arr1(1 to 10) as date
  2. 'here's the code where you fill the dates into the array
  3. dim i as integer
  4. dim tmp1 as date
  5.  
  6. tmp1=arr1(1)
  7. for i = 2 to 10
  8.     if arr1(i) > tmp1 then tmp1=arr1(i)
  9. next
  10. msgbox tmp1
HTH
Newbie
 
Join Date: Jun 2008
Posts: 1
#3: Jun 25 '08

re: how to find the greatest date in a arry


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

Expand|Select|Wrap|Line Numbers
  1. ' sort the date array
  2. Array.Sort(dates)
  3.  
  4. ' your highest date will be:
  5. dates(dates.GetUpperBound(0))
  6.  
  7. ' your lowest date will be:
  8. dates(0)
  9.  
Reply