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, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
Holding back urine or excrement does not affect one's fast. However, there is a difference of opinion among scholars as to the validity of the prayer of a person who holds back urine or stool while offering it. The preponderant opinion, however, is that the prayer is valid if a person does so.
Allaah Knows best.