The method you are describing sounds like relative dating, specifically using the principle of stratigraphy. In geology, this principle states that in an undisturbed sequence of sedimentary rocks, the oldest layers will be at the bottom (lower layers) and the younger layers will be at the top (upper layers). This is known as the Law of Superposition.
When geologists find a rock layer that is between older and younger layers, they can infer its relative age within that sequence. This method helps to establish a timeline of geological events and can provide context for the environment in which the rock was formed, even though it does not provide a precise date.
In addition to superposition, geologists often utilize other principles, such as the Principle of Original Horizontality (which states that layers of sediment are originally deposited horizontally), and the Principle of Cross-Cutting Relationships (which indicates that if a geological feature cuts through another, it must be younger than the feature it cuts through).
For more precise dating, geologists may also use radiometric dating, which can provide absolute ages based on the decay of radioactive isotopes within the rocks.