Depends on what you eat. Proteins and carbs should be eaten 30-45 minutes prior to exercise. Things like Arginine that come from fruit can be eaten 15-30 minutes prior to exercise.
After a workout, it is highly important to replace glycogen levels by eating simple carbs (sugar) which comes from waxy maize, starches, fruits, and white bread. This causes an Insulin spike so nutrients can be fed to the muscles rapidly. About 30-45 minutes later, you want slower carbs and fat to maintain that level of insulin for the next hour or two.
I would eat an hour and a half before, by then the calories and carbohydrates have started to work on your body and you will have more energy, plus the nutrients will start muscle repair as soon as you finish working out, but eat within an hour of working out so your body has resources to repair it with.
If you've just eaten a meal , wait around 30 minutes - 1 hours depending how big the meal is. If it's just a snack , like yogurt or a granola bar , maybe 10 minutes just to let it settle.
It should be an hour before if you are going for swimming and two hours before doing any other aerobics or tough exercise ahead. Hope this helps you
when you feel like you can comfortable exercising without your stomach hurting.