There is a lot of variability in how fast milk will go bad.
How long the milk has been opened
Pasteurized vs ultra-pasteurized
Temperature the milk is kept at
Thermal cycling: how long and how often is it kept above 40º
Where in the fridge it is kept. The door will have more thermal cycling than a shelf, higher shelves tend to be warmer than lower ones.
All of these influence how long milk stays good. The big date on the top is used by grocers to determine when it can't be sold. If you look closer there will be text to the effect of, "Use within 7 days after opening". This isn't a guarantee. Leaving the carton out while you cook will allow it to go bad faster, as will keeping it in the door. Also if your fridge is too warm for some reason, things will spoil faster.
The given date is a sell by date, like others said. What determines the date the milk will actually expire, is the conditions it was stored in. If it was a bit warmer than usual it can expire a week early. Other times, it can expire after the given date. It also matters when you actually opened the bottle. This is why every time you use milk you should smell it (or taste it) before use. the first thing that goes off in milk is the taste - this is because the germs cause fermentation before it is actually unsafe to consume.
The date stamped on milk cartons is neither an expiration date, nor a best by date (at least in the USA). Milk cartons are stamped with a sell by date. This is distinctly different. This is used solely to designate when the store must sell it by. The date the milk goes bad is some time after that.
From personal experience opened milk keeps in my refrigerator for 7-10 days beyond the sell by date. Smell your milk before drinking or using it. Obviously if it's chunky it's also well past bad.
With regards to sell by dates they are generally specified to give the "average" consumer time to consume the product once purchased.
In addition to the things others have mentioned, how the milk is handled during shipping can have an impact on whether or not it lasts to the best before date. Most of the time it goes from one refrigerator to another, but if a driver gets busy and leaves it sitting out for a while and if the store also leaves it out for a while, it can warm up enough to shorten the lifespan.
The rule of thumb a few decades ago was: pasteurized milk has 2 weeks from out of the cow until spoiled. I imagine that depending on different variables (such as those listed by sysadmin1138) and improved technology, you might get up to about 3 weeks total.
Based on this highly scientific reference source, I can assume they feed people whatever the food or drink is, and then once people start getting ill, they subtract one day for the shelf life time they will add to the production date -