Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bayhaqi:5338Abū al-Ḥasan Muḥammad b. al-Ḥusayn al-ʿAlawī > Abū Ḥāmid b. al-Sharqī > Muḥammad b. Yaḥyá > ʿAbd al-Ṣamad b. ʿAbd al-Wārith > Shuʿbah > Ayyūb And Budayl b. Maysarah > Abū al-ʿĀliyah > ʿAbdullāh b. al-Ṣāmit > Abū Dhar Rafaʿah > Ḍarab Fakhidhī

[Machine] Pray the prayer at its appointed time, then leave. But if you are in the mosque and the prayer has been established, then pray with them.  

البيهقي:٥٣٣٨أَخْبَرَنَا أَبُو الْحَسَنِ مُحَمَّدُ بْنُ الْحُسَيْنِ الْعَلَوِيُّ أنبأ أَبُو حَامِدِ بْنُ الشَّرْقِيِّ ثنا مُحَمَّدُ بْنُ يَحْيَى ثنا عَبْدُ الصَّمَدِ بْنُ عَبْدِ الْوَارِثِ ثنا شُعْبَةُ عَنْ أَيُّوبَ وَبُدَيْلُ بْنُ مَيْسَرَةَ عَنْ أَبِي الْعَالِيَةِ عَنْ عَبْدِ اللهِ بْنِ الصَّامِتِ عَنْ أَبِي ذَرٍّ رَفَعَهُ قَالَ ضَرَبَ فَخِذِي وَقَالَ كَيْفَ أَنْتَ إِذَا بَقِيتَ فِي قَوْمٍ يُؤَخِّرُونَ الصَّلَاةَ عَنْ وَقْتِهَا؟ ثُمَّ قَالَ

صَلِّ الصَّلَاةَ لِوَقْتِهَا ثُمَّ اخْرُجْ فَإِنْ كُنْتَ فِي الْمَسْجِدِ فَأُقِيمَتِ الصَّلَاةُ فَصَلِّ مَعَهُمْ  

أَخْرَجَهُ مُسْلِمٌ فِي الصَّحِيحِ مِنْ حَدِيثِ شُعْبَةَ عَنْ بُدَيْلِ بْنِ مَيْسَرَةَ مُسْنَدًا