Calculate time between 2 data of a sensor I'm working on a project in my university and I'm having a trouble in calculate time. I have a conveyor and an IR sensor which I use to calculate the maximum and minimum distances of a box when it is moving on the conveyor. Then I want to calculate the time between the max and min distances of box. I have used millis() for timing but it is not accurate.
Here is my code:

int IRpin = 0;
float volts, distance,firstdata;
int k = 0;
float min;
float mang[150];
int m;
void setup() {
Serial.begin(9600);
}

void loop() {
volts = analogRead(IRpin) * 0.0048828125;
distance = 13 * pow(volts, -1.10);
if (distance &lt; 20)
{
Serial.println(distance);
mang[k] = distance;
k++;
}
else
{
if (k &gt; 0)
{
  min = mang[0];
  for (int i = 1; i &lt; k; i++)
  {

    if (min &gt; mang[i])
    {
      min = mang[i];
      m = i;
    }
  }
  firstdata=mang[1];
  }


I store data the sensor send to me in an array. Now I want to calculate the time between firstdata [mang(1)] and [(min)]. I use 0A41SK Sharp IR sensor.
Thank you for your time and sorry for my bad english.
Ok, yea...Please format this a little better (properly tabbed line spacing and such), and comments would go a long way to understanding this, because chances are people don't want to invest the time to decipher what's going on here without them. I'm not entirely sure what is going on here, but I'll just suggest what I would do in my understanding of the question, which is how to detect what the minimum and maximum value of the distance is and record the time at which each of these moments occurred. 

I would have a float value to store the maximum and minimum distance as well as their times, and simply on every iteration of the loop check if the position was greater than the previous maximum distance or shorter than the previous minimum distance. If either of those are true, set the maximum/minimum distance to the current position and set the maximum/minimum distance time to the current time, using millis(). There's no reason I can see, if I'm understanding this correctly for an array to store all the data, it's just taking up memory space from what I see.

Hope this helps a bit, and, if I'm totally off base, again I'll emphasize the utility of comments in readability. Hope this helps and good luck.