Does within mean before or after? Or does it mean both? For example,
Do not drink or eat within an hour of these pills.
Within is a single word. In the sense of your example, it means something like during, or before the end of:
do not drink or eat during the hour before or the hour after you take these pills.
I want to have been promoted within a year of joining the company.
I want to live within five miles of the office.
Within the boundary of my lands, I am king.
See definition on Merriam-Webster.
Edited to point out that it applies to the hour before as well as the hour after. The other answer is better.
do not drink or eat with in an hour of these pills
'Within' means inside some sort of time frame... so this sentence literally means that you must wait until an hour after eating before taking the pills, and must not eat until an hour after taking the pills.
In my experience, this is very usual advice - I don't think it was intended this way; it could mean you need to wait for an hour after eating before taking the pills, or it could mean that you have to wait for an hour after taking the pill to eat.
I would interpret it as the latter, but it isn't entirely clear.
Example : I am going to reach Tokyo within an hour. specificaly says that it will takeme less than an hour or so to reach tokyo.