Jarir reported, "We were sitting one night with the Prophet ﷺ when he looked at the moon on the fourteenth night and said, 'You will surely see your Lord just as you see this moon. You will have no difficulty in seeing Him. So if you are able not to be overcome from praying before sunrise and before sunset, then do so.'"Then he recited, "And glorify the praise of your Lord before the rising of the sun and before its setting" [Qaf 50:39].
قال كنا جلوسا ليلة مع النبي ﷺ فنظر إلى القمر ليلة أربع عشرة فقال: إنكم سترون ربكم كما ترون هذا، لا تضامون في رؤيته، فإن استطعتم أن لا تغلبوا على صلاة قبل طلوع الشمس وقبل غروبها فافعلوا ثم قرأ: {وسبح بحمد ربك قبل طلوع الشمس وقبل الغروب}
Bukhari reported it in tafsir (4851) and Muslim in the book of mosques and places of prayer (633), both through the route of Ismail bin Abu Khalid, who said, Qays bin Abu Hazim told us, I heard Jareer bin Abdullah say, and he mentioned it, the wording being Bukhari's, while Muslim's wording is similar.His saying, "and glorify your Lord with praise" means pray while praising Allah. His saying, "before the rising of the sun" refers to the dawn prayer. His saying, "and before its setting" means from after sunrise until just before sunset, referring to the Dhuhr and Asr prayers. His saying, "and glorify Him during part of the night" means the Maghrib and Isha prayers. His saying, "and after sujud" means glorify Allah after the prayers, and this has come in the sahih hadith.