The Prophet ﷺ said, "If one of you reaches the first prostration of the afternoon prayer before the sun sets, let him complete his prayer. And if he reaches the first prostration of the dawn prayer before the sun rises, let him complete his prayer."
أخبرنا عمرو بن منصور قال حدثنا الفضل بن دكين قال حدثنا شيبان عن يحيى عن أبي سلمة
عن النبي ﷺ قال إذا أدرك أحدكم أول سجدة من صلاة العصر قبل أن تغرب الشمس فليتم صلاته وإذا أدرك أول سجدة من صلاة الصبح قبل أن تطلع الشمس فليتم صلاته
Bukhari transmitted it, hadith no. 556. See the previous hadith, from Abu Naeem Fadl bin Dukayn, with the same wording, and it is in Kubra, hadith no. 1504.Muslim also transmitted it, hadith no. 607, through another route from Abu Salama with the same wording, as mentioned in the previous hadith.