Abu Dharr reported,

I asked, "Messenger of Allah, which mosque was built first?"He said, "The Sacred Mosque."I asked, "Then which?"He said, "Then the Aqsa Mosque."I asked, "How long was there between them?"He said, "Forty years." Then he said, "Wherever the time of prayer overtakes you, pray, for the earth is a mosque for you."

Bukhari 3425

Sahih

حدثني عمر بن حفص حدثنا أبي حدثنا الأعمش حدثنا إبراهيم التيمي عن أبيه

عن أبي ذر رضي الله عنه قال

قلت يا رسول الله أي مسجد وضع أول قال المسجد الحرام قلت ثم أي قال ثم المسجد الأقصى قلت كم كان بينهما قال أربعون ثم قال حيثما أدركتك الصلاة فصل والأرض لك مسجد

البخاري 3425صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Hadiths of the prophets
Chapter
Saying of Allah the Exalted, "And We gave to Dawud, Sulayman, an excellent servant. Indeed, he was one repeatedly turning back to Allah"
Numbering
Darussalam 3425
Bukhari 3425