Yes, you can get diarrhea when you are stressed out. Studies show a relationship between diarrhea (a symptom of IBS-irritable bowel syndrome) and anxiety (Lee et al., 2009). Also, studies show that treating the anxiety can reduce the diarrhea associated with IBS (Lan et al., 2014).
So when you are stressed out and have diarrhea, you can address the diarrhea by reducing your stress. Various relaxation strategies can help to reduce your stress, and hence diarrhea.
Efficacy of tandospirone in patients with irritable bowel syndrome-diarrhea and anxiety. Lan L, Chen YL, Zhang H, Jia BL, Chu YJ, Wang J, Tang SX, Xia GD. World J Gastroenterol. 2014 Aug 28;20(32):11422-8.
Irritable bowel syndrome is strongly associated with generalized anxiety disorder: a community study. Lee S, Wu J, Ma YL, Tsang A, Guo WJ, Sung J. Aliment Pharmacol Ther. 2009 Sep 15;30(6):643-51.