your surgeon and anesthesiologist tell you that you can eat last.
They also will tell you if you can drink water. Usually it is at least 8-12 hours with no food, no water except a sip for medications. And as I just learned from my recent surgery, no gum as it gets the gastric juices going. The whole purpose of this is so you don't vomit stomach contents and get them into your lungs.