The dating is done via radiometric techniques, which provide an acurate estimate of the absolute age, in millions of years. The fossils only provide a relative order of the ages of strata they are found in (from oldest to youngest). It is entirely mistaken to believe the circular argument that the fossils provide the age of the strata, and the strata provides the ages of the fossils, and that the dates are somehow "made up", as alleged by the likes of Hans B.
You don't need "organic material" to do the dating. Actually, most fossils don't have any organic material left, having been recrystallized and altered, leaving behind imprints or traces as opposed to the original remains. Furthermore, the oft-quoted Carbon14 method only works over a period going back a hundred thousand years or so (due to it's relatively short half life) whereas geological processes are measured in millions to hundreds of million years. So we need isotopes with very long half lives; in particular K/Ar, U/Pb & Rb/Sr.
Now none of these isotopes are particularly associated with fossils, so how is it done??? The radioactive isotopes are measured, and ages calculated, on rock types (ideally unaltered igneous rocks such as lavas) that were formed at the same time as fossiliferous sedimentary strata in close proximity. This provides a time framework, and the ultimate ages.
The fossils, many of which are easily recognizable and show distinct changes in geological time due to evolution, can be used to provide the correct relative sequencing of geological stata in which they are found. This is a relative timescale, not an absolute one. The correct age sequence of geological strata, and the division into eras & periods & more (e.g. Jurassic, Cretaceous) was deduced by geologists well over 100 years ago. However it was only a relative sequence, and the geologists had no real clue as to the absolute ages (although some of the more far-sighted geologists knew that the timescale was vast...). It was only with the invention of the radiometric technique that the truly vast and remarkable timescales were established beyond doubt.
Of course, there are, and will always be, gaps in knowledge and extrapolations made. The geological record is actually incredibly complex, as hinted at by Jamie M with great foresight. There are usually big sections missing due to tectonic activity, uplift and erosion - what geologists call "unconformities" - and furthermore, many rock types are either not condusive to fossilization or didn't contain much in the way of living remains in the first place. And many fossils are no good for sequential dating anyway, particularly those that did not evolve rapidly, or were restricted to living in certain limited palaeo-environments. Big gaps in the geological record are (a) very common, and (b) entirely to be expected, so please do not believe the pseudo-creationist propaganda put out by the likes of Hans B (who seems to have not even a basic level of geological knowledge) that would have you believe otherwise.