Abu Dharr reported,

I asked, "Messenger of Allah, which mosque was established on earth first?"He replied, "The Sacred Mosque."I asked, "Then which?"He replied, "Masjid al-Aqsa."I asked, "How long was there between them?"He replied, "Forty years. Then wherever the time of prayer overtakes you after that, pray, for the merit lies in it."

Bukhari 3366

Sahih

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

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

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

البخاري 3366صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Hadiths of the prophets
Chapter
Yaziffun means walking quickly
Numbering
Darussalam 3366
Bukhari 3366