Depends. Staph: lasts 1-3 days. Viral gastroenteritis can last a week. Anything longer needs evaluation. See doc if fever, bleeding, severe symptoms, i.e. Can't keep anything down or in, other health issues, e.g. Diabetes, chronic illnesses, elderly, very young, rash, joint pains, recent travel, antibiotics in past 2-3 months, etc to make sure of the diagnosis, and get appropriate rx, avoid dehydratio, .
Food poisoning. This would depend on the organism causing the food poisoning. It could be hours to days. If it lasts more than 48 hours or if there is blood in the stool follow with a local physician or ER.