Yahya bin Maymun al-Hadrami relates that Sayyiduna Sahl bin Sa'd al-Sa'idi (may Allah be pleased with him) came and stood by us while we were in the mosque. Sahl (may Allah be pleased with him) said: I heard the Messenger of Allah (peace and blessings be upon him) say: "Whoever sits in the mosque waiting for the prayer is counted as being in prayer."
Hadith Referenceالمعجم الكبير للطبراني / باب السين / 5988