“Forty years. Then, wherever you are when prayer becomes due, pray, for therein lies the merit.” This is how I copied it from al-Bukhārī.
The hadith master reported in his book al-Mustaqsā, through a chain of transmission from Abū Dharr—may Allah be pleased with him—who said:
I asked, “O Messenger of Allah, which mosque was first established on earth?” He replied, “The Sacred Mosque.” I asked, “Which came next?” He replied, “Al-Aqsā Mosque.” I asked, “How much time elapsed between the two?” He replied, “Forty years.”
He then said, “Al-Farrā added: ‘Wherever you are when prayer becomes due, pray, for that place is a mosque.’” He then said, “This is an authentic hadith, recorded in both Sahīhs, and also by al-Nasā’ī and al-Qazwīnī.”
I copied it from the chapter “Which Mosque Was First Established on Earth?” in the section “The Virtues of Bayt al-Maqdis.” He then presents the chapter “Bayt al-Maqdis Was Built upon an Ancient Foundation.” He said: The foundation was the one laid by Shem son of Noah—peace be upon them both—and it was then built by David