Permanent magnets, such as those made of materials like neodymium, samarium cobalt, or ceramic ferrite, do not typically "run out" of magnetism over time. They can retain their magnetic properties for a very long period, often many years or even decades.
The strength of a magnet, however, can gradually decrease over time due to various factors. These factors include exposure to high temperatures, strong magnetic fields, mechanical shocks, and corrosion. Additionally, if you subject a magnet to a demagnetizing force or heat it beyond its Curie temperature (the temperature at which it loses its magnetic properties), its magnetism can be significantly reduced or completely eliminated.
Under normal conditions, simply holding two magnets together or in close proximity does not cause a significant loss of magnetism. The magnetic field of a magnet is essentially a property of its material composition and arrangement of its atomic or molecular structure, and it does not typically degrade by being in contact with another magnet.
Therefore, you can expect permanent magnets to maintain their magnetic strength for an extended period, and there is no specific time limit for how long you need to hold them together before they lose their magnetism.