William ran for 2 hours.
<h3>What is the distance of an object?</h3>
The distance of an object is the amount of speed covered with respect to time.
Mathematically:

From the given information:
Elliot ran for 8 miles in x speed, the time at which he ran can be computed as:
hours
William ran for 12 miles in x speed, the time at which he ran can be computed as:
hours
If Elliot finished his race 40 minutes fewer than William, then we have:

Therefore, the distance at which William ran for can be computed by using the relation:


By solving for x,

By cross multiply;
2x = 12
x = 12/2
x = 6 miles per hour
Thus, William ran for:
= 12 miles/ 6 miles per hour
= 2 hours
Learn more about distance here:
brainly.com/question/17273444