Abu Dharr reported,

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

Ahmad 21390

Sahih

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

عن أبي ذر قال

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

أحمد 21390صحيح
Contents
Reference
Commentary
Ayat
Collection
Musnad Ahmad
Book
Abu Dharr Ghifari
Numbering
Darussalam 21390
Ahmad 21390