Abdullah bin Abi Qays said: I asked Sayyidah Aishah (may Allah be pleased with her) what the Messenger of Allah (peace and blessings be upon him) used to do in a state of janabah: did he (peace and blessings be upon him) perform the ritual bath before sleeping, or sleep before performing the ritual bath? She said: He (peace and blessings be upon him) did both; sometimes he (peace and blessings be upon him) performed the ritual bath and then slept, and sometimes he (peace and blessings be upon him) performed ablution and then slept. I said: 'Alhamdu lillahil-ladhi ja'ala fil-amri sa'ah' (All praise belongs to the One who has made room in the matter).
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 970