The question in both cases is storage.
With the *right* storage, *both* mediums are able to last at least 20 years.
However, magnetism might wear itself off some time, just look at floppies. CDs don't have this - unless they get scratches.
I have here a closed box ccontaining backups I made around 2001/2002. These rewritables are still readable.
But they use material that might not last that long. The material the laser "writes" upon. So to say.
In manufactured CDs, the only material that can be deterogare throughout time is the plastic itself.
But in the end ... you would have to hammer everything into stone to last. And neither sandstone, nor limestone.
And even stone isn't forever.