عَنْ أَبِي ذَرٍّ رَضِيَ اللَّهُ عَنْهُ قَالَ قُلْتُ يَا رَسُولَ اللَّهِ أَيُّ مَسْجِدٍ وُضِعَ فِي الْأَرْضِ أَوَّلُ قَالَ الْمَسْجِدُ الْحَرَامُ قَالَ قُلْتُ ثُمَّ أَيٌّ قَالَ الْمَسْجِدُ الْأَقْصَى قَالَ قُلْتُ كَمْ بَيْنَهُمَا قَالَ أَرْبَعُونَ سَنَةً ثُمَّ قَالَ أَيْنَمَا أَدْرَكَتْكَ الصَّلَاةُ فَصَلِّ فَهُوَ مَسْجِدٌ
It is narrated from Sayyiduna Abu Dharr (may Allah be pleased with him), he says: I asked, "O Messenger of Allah! Which mosque was built first?" He (peace and blessings be upon him) said: "Al-Masjid al-Haram." I asked: "Then which was built after that?" He (peace and blessings be upon him) said: "Al-Masjid al-Aqsa." I asked: "What was the time span between the two?" He (peace and blessings be upon him) said: "Forty years." Then he (peace and blessings be upon him) said: "Wherever the time of prayer finds you, perform the prayer there, for that is a mosque."