We were sitting with the Messenger of Allah ﷺ when he looked at the moon on the night of the full moon and said, "You will see your Lord just as you see this moon, with no difficulty in seeing Him. So if you are able not to be overcome from praying before the rising of the sun and before its setting, 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 narrated it in the Book of Tawhid, chapter "The saying of Allah Most High, 'Faces that day will be radiant'" and so on, hadith no. 7434 and 7435, and others, and Muslim in the Book of Mosques, chapter on the excellence of the Fajr and Asr prayers and maintaining them, hadith no. 633, from the hadith of Ismail, with the same chain.