Dinosaurs lived on Earth for about 175 million years, until they were entirely wiped out by the K-T extinction event at the end of the Cretaceous Period. They lived during the Mesozoic Era, and examples of dinosaurs can be found in all three periods of that era.
If birds are counted as dinosaurs, then dinosaurs never actually went extinct at all and continue to survive as a group into the present day, making for a total of 250 million years. However, no non-avian dinosaurs are known to have survived the Cretaceous extinction event. Although the first dinosaurs appeared early in the Triassic Period, they did not diversify extensively until the Jurassic Period.