Bukhari :: Book 4 :: Volume 55 :: Hadith 636

Narrated Abu Dhaar:

I said, "O Allah's Apostle! Which mosque was built first?" He replied, "Al-Masjid-ul-Haram." I asked, "Which (was built) next?" He replied, "Al-Masjid-ul-Aqs-a (i.e. Jerusalem)." I asked, "What was the period in between them?" He replied, "Forty (years)." He then added, "Wherever the time for the prayer comes upon you, perform the prayer, for all the earth is a place of worshipping for you."

Source materials are from the University of Southern California MSA site
Hadith eBooks converted from Imaan Star