Clean his cage and make sure he has plenty of fresh water and fresh food. Get rid of any old food and water. Sometimes too much vitamin C can cause diarrhea, so if you have been giving him food with a lot of C in it, then cut back on that. Give him a mineral lick too. That will help him recover. Diarrhea is often caused by dirty cage conditions, so cleaning the cage is the most important thing. Contaminated or spoiled food is also a possibility. Be sure to wash the water bottle and give him clean water often. Don't just add new water to the old water. Water that sits still can grow bacteria, and the chlorine that is put in tap water to kill bacteria will separate from the water and turn into a gas which you will see as bubbles on the side. So you see that the water will expire. I would not use bottled water, since once opened, it will expire faster since it does not have chlorine in it. But if you change the water every day, then bottled water is fine if you want to pamper your pet.
I think my hamster has diarrhea because he isn't eating any of the food I'm giving him. Plus his eyes are now always half-closed and his back is crouched up in a ball like he's in pain or something. D: And I think I saw him sneeze a couple of times. Today my hamster just weirdly twirled around in a circle many times. Its weird because I never saw him do that before.
If your hamster is having diarrhea its probably the cage so often you should clean its cage, water , bedding, toys and food .