From the TierneyLab blog, NYT.com ("Why is there a weekend?" quiz question)
E3: Why are there seven days in a week?
The seven day week is traced back to at least Babylonian times, a civilization known for its detailed sky watching. As several readers noted, we are not exactly sure why a week is divided into seven days, but one idea with historical merit is that even very ancient societies would have noticed objects that moved with respect to the fixed stars in the night sky. They observed seven objects that “wandered” relative to the stars: the Sun, the Moon, Mercury, Venus, Mars, Jupiter and Saturn. Seven objects, seven days of the week. It is probably also significant that the number 7 is almost (7×4=28) evenly divisible in to the number of days required for a full cycle of lunar phases (29.5 days), and almost (7×52=364) evenly divisible into the number of days in a year (365.25).
We still see the names of the “wanderers” in English (Sunday, Monday), and even more clearly in other languages: Monday: lunes (Moon), Tuesday: martes (Mars), Friday: viernes (Venus) in Spanish, for example. Since all other parts of our calendar are related to motions in the night sky, a link between seven days and these seven objects might not be too surprising. A year is the time that it takes our planet to orbit the Sun. And before we understood that we were orbiting the Sun, it was the time it took for the Sun to move through a great circle around the sky (the ecliptic) and come back to the same stars. A lunar month is the time it takes for the moon to go through its well-known cycle of phases. A day is how long it takes for the Earth to rotate on its axis.
As several readers also noted, the need for a unit of time that is greater than a day, but less than a month may have origins in early agrarian societies and agreed-upon market days.