comparing 2 accelerometer values at different time points

hi everyone im new to arduino and using sensors and such.

I know how to collect data from the accelerometer and get it to read off live data.
what am i am now trying to figure out is how to efficiently save data from 2 different time points and store them for use.

double avg_acceleration(Sample_obj & first_sample, Sample_obj & second_sample) {
    double acceleration[3] = {-1, -1, -1};

    acceleration[0] = second_sample.x - first_sample.x;
    acceleration[1] = second_sample.y - first_sample.y;
    acceleration[2] = second_sample.z - first_sample.z;}

i have created this so far but seem to be having a brain fart to how to insert use my accelerometer with it. i have labeled the time points first_sample and second_sample. ideally the time between first_sample and second_sample is 50 milliseconds. so i guess to restate my question, how do i read the sensors and insert accelerometer data from 2 time points into values in order to compare them.

how do i read the sensors and insert accelerometer data from 2 time points into values in order to compare them.

Read the first value. Put it into a variable (possibly in an array). Set a boolean variable to true to flag that timing is taking place. Save the value of millis() as the start time. Keep going round loop but do not take another reading if the boolean is true. Once the timing period has elapsed (current time - start time >= period) take the second reading and put it into another variable or array level. Do what you need with the two values.