All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
It is lawful for a person in a state of sexual defilement from wet dreams or after having sex with one’s wife, to delay his Ghusl (ritual bath) till the time of the Fajr prayer and then performs Ghusl, and this does not affect his fasting according to the view of the majority of the scholars . ‘Aa’ishah said: “I testify that the Prophet used indeed, to stay in the state of sexual defilement not from wet dreams, till the time of the Fajr prayer and fast that day”. [Al-Bukhari and Muslim] But you should perform Ghusl before the expiry of the prescribed time of the Fajr prayer, which is before sunrise. The Prophet was asked: “Which is the best act?” and he replied: “It is to perform the prayer at its prescribed fixed time”. [Muslim]
Allah knows best.