The spore-forming, gram-negative bacteria Clostridium difficile can cause severe intestinal illness. A striking increase in the number of cases of C. difficile infection (CDI) among hospitals has highlighted the need to better understand how to prevent the spread of CDI. In our paper, we modify and update a compartmental model of nosocomial C. difficile transmission to include vaccination. We then apply optimal control theory to determine the time-varying optimal vaccination rate that minimizes a combination of disease prevalence and spread in the hospital population as well as cost, in terms of time and money, associated with vaccination. Various hospital scenarios are considered, such as times of increased antibiotic prescription rate and times of outbreak, to see how such scenarios modify the optimal vaccination rate. By comparing the values of the objective functional with constant vaccination rates to those with time-varying optimal vaccination rates, we illustrate the benefits of time-varying controls.