This topic has been much debated, especially in this forum. There is no right answer, but there are different things you can do.
Here are what I've taken away from some discussions.
1. Play until you feel the table's potential profit isn't worth it's risk. Players are not paying off your monsters
2. Play until you can't play well anymore. Basically fatigue sets in.
3. Play until you hit a certain amount of time/number of
hands. Set out saying "I want to play 1500 hands online today." Or "I want to play for six hours at the live table."
4. Play until you have a certain amount of money, or have lost a certain amount of money. Note: This is usually best when you have a high and low limit for yourself. For instance, I'm playing a $300 buy-in game, I'll play until I'm up two buy-ins or down two-buy-ins. When I play in tournaments, I'll allow myself a buy-in at the $300 buy-in game before, where I have a real time limit to contend with, and possibly a $300 buy-in after, but usually a break is in order after any long amount of poker.
These are just some examples. Personally if I go to the casino at night, I play where the action is, I'm a self proclaimed deep-stack hunter, so I play very tight until I'm up a buy-in and can knock a couple buy-ins off a deepstack. If there are multiple deep stacks, I keep waiting until they get a hand they can't fold and have'em pay me off.
I've had set over set (top two, no less), trips over Aces, a flopped flush vs a way behind overpair, etc. So it doesn't make sense for me to go with less than four buy-ins, or when the deep stacks start leaving.