It is narrated from Sayyiduna Abdullah bin Arqam (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "When one of you needs the toilet and the time of prayer has come, let him first go to the toilet."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 14057