Mūsā ibn Ismā’īl narrated to us; ‘Abd al-Wāḥid narrated to us; al-A’mash narrated to us;
Ibrāhīm al-Taymī narrated to us from his father, who said: I heard Abū Dharr (may Allāh be content with him) say: I said, “O Messenger of Allāh ﷺ, which mosque was the first to be established on the earth?” He said: “Al-Masjid al-Ḥarām.” I said, “Then which one?” He said: “Al- Masjid al-Aqṣā.” I said, “How long was between them?” He said: “Forty years.” Then he said: “Wherever the time of prayer comes upon you, then pray there, for the virtue is in it.”
حَدَّثَنَا مُوسَى بْنُ إِسْمَاعِيلَ، حَدَّثَنَا عَبْدُ الْوَاحِدِ، حَدَّثَنَا الأَعْمَشُ، حَدَّثَنَا إِبْرَاهِيمُ التَّيْمِيُّ، عَنْ أَبِيهِ، قَالَ سَمِعْتُ أَبَا ذَرٍّ ـ رضى الله عنه ـ
قَالَ قُلْتُ يَا رَسُولَ اللَّهِ، أَىُّ مَسْجِدٍ وُضِعَ فِي الأَرْضِ أَوَّلُ قَالَ " الْمَسْجِدُ الْحَرَامُ ". قَالَ قُلْتُ ثُمَّ أَىٌّ قَالَ " الْمَسْجِدُ الأَقْصَى ". قُلْتُ كَمْ كَانَ بَيْنَهُمَا قَالَ " أَرْبَعُونَ سَنَةً، ثُمَّ أَيْنَمَا أَدْرَكَتْكَ الصَّلاَةُ بَعْدُ فَصَلِّهْ، فَإِنَّ الْفَضْلَ فِيهِ "
Reference: Sahih Al Bukhari 3366