Ideally you should eat before and after your workout.
Personally I like to eat something dense in carbohydrates 30 minutes to an hour before my workout. That allows me to
1. Use the easily accessible energy from the carbs for a better workout.
2. Burn the carbs before they are turned to fat.
3. Not feel hungry before my workout but also not feel so full that it slows me down.
That doesn’t mean you have to have a big meal before your workout; sometimes I’ll have a small bowl of oatmeal for example, or if I’m not very hungry just a granola bar.
I think eating 2 hours before your workout, as a lot of people suggest, does not make sense. Those carbs are not going to be as beneficial at that point and are more likely to start being stored as fat the longer they sit there.
Also, everyone’s body is different so be sure to listen to your body. Do a little trial and error to figure out what makes your workouts feel the strongest.
In general though, the purpose of pre-workout nutrition is energy (which comes best from carbs) and the purpose of post-workout nutrition (to be consumed somewhere within 1 hr after your workout) is recovery and growth, which is where protein comes in.
Hope this helps!