The timescales and mechanisms for the formation and chemical differentiation of the planets can be quantified using the radioactive decay of short-lived isotopes. Of these, the (182)Hf-to-(182)W decay is ideally suited for dating core formation in planetary bodies. In an earlier study, the W isotope composition of the Earth's mantle was used to infer that core formation was late (> or = 60 million years after the beginning of the Solar System) and that accretion was a protracted process. The correct interpretation of Hf-W data depends, however, on accurate knowledge of the initial abundance of (182)Hf in the Solar System and the W isotope composition of chondritic meteorites. Here we report Hf-W data for carbonaceous and H chondrite meteorites that lead to timescales of accretion and core formation significantly different from those calculated previously. The revised ages for Vesta, Mars and Earth indicate rapid accretion, and show that the timescale for core formation decreases with decreasing size of the planet. We conclude that core formation in the terrestrial planets and the formation of the Moon must have occurred during the first approximately 30 million years of the life of the Solar System.