We were sitting with the Messenger of Allah ﷺ when he looked up at the moon on the night of Badr, the fourteenth night, 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 sunrise and before sunset, then do so."Then he recited this verse, "And glorify the praise of your Lord before the rising of the sun and before its setting" [Ta-Ha 20:130].
حدثنا عثمان بن أبي شيبة حدثنا جرير ووكيع وأبو أسامة عن إسمعيل بن أبي خالد عن قيس بن أبي حازم
كنا مع رسول الله ﷺ جلوسا فنظر إلى القمر ليلة البدر ليلة أربع عشرة فقال إنكم سترون ربكم كما ترون هذا لا تضامون في رؤيته فإن استطعتم أن لا تغلبوا على صلاة قبل طلوع الشمس وقبل غروبها فافعلوا ثم قرأ هذه الآية ف {سبح بحمد ربك قبل طلوع الشمس وقبل غروبها}
Bukhari narrated it in the tafsir of Surah Qaf, in the chapter on His saying, "and glorify your Lord's praise before the rising of the sun and before its setting," hadith no. 4851, from the hadith of Jareer bin Abdul-Hameed.Muslim narrated it in the Book of Mosques, in the chapter on the merit of the two prayers of dawn and Asr and adhering to them, hadith no. 633, from the hadith of Waki and Abu Usama, through the same chain.