Let's start by saying that I work in a grain store.
Sometimes we have bags that stay in the warehouse for months. If they are still good then we sell them, however, we do sometimes need to get rid of bags. All grain can be damaged by grain mites, which are so small that they look like a dusty yellow powder until closer inspection shows that they are actually moving...yuck! We keep large fans blowing all through the warmer months to keep good airflow and avoid the mites. Sweet feeds spoil faster than pelleted feeds. If you can see an oily residue beginning to seep through the bag, then it is definitely bad. It also depends on how the grain is stored. If it is off the ground and in a dry, well-ventilated area, then it can keep for many months, if not, then it can spoil in even a couple weeks or sooner. I know that I had a bag of sweet feed that I had to buy when I got a new horse (to transition him over to his new feed). I wanted to donate it, but because the extra just ended up sitting in the bag on my tack room floor for a month, I ended up just having to throw it out. Now if it had been stored properly, it would likely have still been good.
So I guess it depends really. I hope this helped you out a bit though.