Approximately 240 million years ago in the late Triassic period. They went extinct (by in large) about 65 million years ago.
Dinosaurs lived in 3 different periods. The first period began about 250 million years ago and it was called the Triassic period. It lasted about 50 million years. Dinosaurs arose part way through, anywhere from 245 million years ago to 200 million years ago. The second period was the Jurassic Period which lasted 56 million years. The final period was the Cretaceous Period which ended 65 million years ago when the dinosaurs disappeared most likely due to a large asteroid collision.