Human hair can endure for several years, often 2 years, before decomposing along with softer tissues. Hair, like fingernails, is made of keratin and is much more durable than skin and flesh.
Decomposition is heavily affected by the environment in which it occurs. While most microbes, rodents and insects do not eat hair or fingernails, they can hasten the overall process. In a sealed grave the entire process occurs much more slowly, sometimes on the order of years. If exposure to soil is direct, or if the corpse is left unburied and exposed to the wind, then decomposition occurs with much greater rapidity.
Keratin resists the enzymes that encourage decomposition. This process is called proteolysis and it breaks down fleshy tissue with extreme rapidity. Environmental stress like moisture and invasive plant growth are more influential in destroying keratin, though eventually the process of decomposition does take its toll on the materials involved.
In some extreme cases when a corpse has been preserved through artificial means, hair and fingernails may endure far longer than is typical. This period can last for decades or even centuries, although it requires a very sterile environment and the careful maintenance of the tomb or sepulcher in question.