Freshly roasted coffee beans begin to lose volatile aromatic compounds the second they are ground. Studies show that the largest percentage of these compounds is lost within the first 15 to 30 minutes after grinding. To prevent rapid flavour loss, grind your coffee only before you brew.
If you use an espresso machine, you can take it one step further with single dosing. Keep your beans in an airtight container like an Aiscape canister, and use scales to weigh out only what you need (typically 18-20g per espresso shot).