Fossils can help determine the relative age of a rock i.e. they can help you tell whether a rock is older or younger than another rock by the fossils within. Generally, the more basic an organism is, the older the rock that contains it is, so for example, if a rock contained a single-celled organism, it is older than a rock that contains a multi-celled organism. Another example is if a rock contains fossils that are 425 million years old, then that rock is older than another rock which contains fossils that are 400 million years old. A third example, if a rock contains fossils that are 425 million years old, then the rock that contains the fossils must be older than the fossils, i.e. older than 425 million years old, for the fossils, which came later, to be preserved in that rock.
Certain fossils, such as ammonites, trilobites and graptolites, are known as index fossils. Because they were so abundant and widespread during a short period of geological time, their presence helps date rocks from that period. For example, ammonites are index fossils for the Jurassic, trilobites are index fossils for the Cambrian and graptolites are index fossils for the Silurian.
They can also give you the absolute age of a rock by using radiometric dating methods.