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.
quran:7:142

And We made an appointment with Moses for thirty nights and perfected them by ˹the addition of˺ ten; so the term of his Lord was completed as forty nights. And Moses said to his brother Aaron, "Take my place among my people, do right ˹by them˺, and do not follow the way of the corrupters."  

And We appointed (read wa-wā‘adnā or wa-wa‘adnā) for Moses thirty nights, at the end of which We would speak to him, after he has fasted ˹during that period˺; that was the month of Dhū’l-Qa‘da. He completed the fast. But when it came to an end, he disliked the ˹bad˺ odour of his mouth and so cleaned his teeth. God then commanded him ˹to fast for˺ another ten nights so that He may speak to him despite the odour in his mouth: as God says, and completed them with ten, nights of Dhū’l-Hijja. Thus was the time appointed by his Lord concluded, the time at which God had promised him to speak to him, as forty (arba‘īna is a circumstantial qualifier) nights (laylatan is for specification); and Moses said to his brother Aaron, when he was departing to the Mount for the communion ˹with his Lord˺: ‘Succeed me, be my deputy, over my people, and be righteous, ˹among them˺ with regard to their affair, and do not follow the way of the agents of corruption’, by consenting with them to acts of disobedience.
القرآن:٧:١٤٢

وَوَاعَدْنَا مُوسَىٰ ثَلَاثِينَ لَيْلَةً وَأَتْمَمْنَاهَا بِعَشْرٍ فَتَمَّ مِيقَاتُ رَبِّهِ أَرْبَعِينَ لَيْلَةً ۚ وَقَالَ مُوسَىٰ لِأَخِيهِ هَارُونَ اخْلُفْنِي فِي قَوْمِي وَأَصْلِحْ وَلَا تَتَّبِعْ سَبِيلَ الْمُفْسِدِينَ  

{وواعدنا} بألف ودونها {موسى ثلاثين ليلة} نكلمه عند انتهائها بأن يصومها، وهي ذو القعدة فصامها فلما تمَّت أنكر خلوف فمه فاستاك فأمره الله بعشرة أخرى ليكلمه بخلوف فمه كما قال تعالى: {وأتممناها بعشر} من ذي الحجة {فتم ميقات ربِّه} وقت وعده بكلامه إياه {أربعين} حال {ليلة} تتميز {وقال موسى لأخيه هارون} عند ذهابه إلى الجبل للمناجاة {اخلفني} كن خليفتي {في قومي وأصلح} أمرهم {ولا تتبع سبيل المفسدين} بموافقتهم على المعاصي.