Before providing an answer to your question, first I want to help you understand what fresh roasted coffee means. It’s important to make better sense of what "fresh" means in general and when talking about freshly roasted beans specifically.
The number one factor that has a direct influence on how long roasted coffee will stay fresh is if you bought whole beans or ground coffee. Ground coffee loses its freshness much faster than whole bean coffee. Why? The main reason is that the whole beans have a larger surface area, so they let out more aromas, the most volatile compounds in coffee. The ground coffee has a much lesser surface area thus it losses its freshness faster.
One way to amplify the taste of your cup is and ensure your coffee remains fresh longer is to buy whole beans. This will cut down on stale air exposure, maximize extraction since you are eliminating over-roasted particles through uniformity in particle size distribution and provide for sublet sweetness due to more oils remaining intact inside each grain of coffee.
So let's come back to our original question. How long do roasted coffee beans stay fresh? If you bought whole bean coffee, roasted within the last 14-21 days, then it will stay fresh for up to 2 months, although I would recommend consuming it within one month.
If however you have bought pre-ground coffee, I would suggest you consume it within a few days as it has already started losing much of its freshness from the moment it was ground.. In this case I'd say find a way of buying whole bean coffee and pay a little extra so you can keep your freshness window at 14-21 days (which is the same as what should apply for any kind of ground roasted coffee no matter how long ago).
And by storing it properly in an airtight container, sealed tight to minimize exposure to oxygen, light and moisture - all factors which cause staling - make sure that your beans are stored away from heat sources like radiators or other hot appliances.
All in all, it's definitely better to buy whole bean coffee, freshly roasted and then grind it yourself before brewing your cup(s). I hope this was helpful. If you have any questions, please let me know!