Yahya bin Maymun al-Hadrami relates: I was sitting in the mosque when Sayyiduna Sahl bin Sa'd (may Allah be pleased with him) passed by me and said: "Shall I not tell you a hadith that I heard from the Messenger of Allah (peace and blessings be upon him)?" I said: "Certainly." He said: I heard the Messenger of Allah (peace and blessings be upon him) say: "Whoever is in the mosque waiting for the prayer is counted as being in prayer."
Hadith Referenceالمعجم الكبير للطبراني / باب السين / 5989