Whole spices will retain their flavor indefinitely, but ground spices begin to lose their flavor and aroma as soon as they are ground. Different spices deteriorate at different rates, with the differences resulting from the different amounts of oil in each product. Oils, like fat delivers flavor and once product is ground, the oil will dissipate.
Now, some spices are so difficult or dangerous to grind that they should always be bought already ground. The different chilies would be a good example because of how strong they can be; fortunately chilies retain their flavor and heat fairly well for up to 10 months.
Herbs will lose their flavors and aromas as they age. Also, as soon as herbs are crushed or cut the oils dissipate, their flavors begin to diminish. The best way to prolong the flavor and intensity of herbs and spices is to keep their containers tightly closed and away from light or heat. Most people prefer glass bottles with tight fitting caps because they have the added advantage of being able to have either caps or fitment lids with openings for sprinkling or spooning out spices while cooking.
The best test for freshness is still to use your nose, as the aroma of herbs and spices is the most important determinant of freshness. Once the aroma is no longer strong, fresh, and fragrant, it is time to get rid of them (should you not realize the importance of fragrance, remember how tasteless food is when you have a cold). Since most spices are harvested ten to twelve months of the year, acquiring fresh products should not be a problem (so long as you buy them from the smaller spice houses, which turn their products over more frequently.