If this is ordinary residential timer, you can replace battery without changing anything.
Just replace battery.
Most timers will hold some or part of the memory during battery changeover... frequently losing no programming if battery change is done quickly, and battery was not completely depleted, and timer is still functional.
If timer function is not restored after battery change, reset timer fully and then reprogram.
If battery change and reset does not work, then timer is probably gone bad.
Most modern timers have reset button, but some require a 2-button sequence to reset.
Other modern timers have a 'battery' but the battery is built into the circuit board and thus not replaceable ... it is rechargeable, like a capacitor ... but when it fails .. the timer needs to be replaced.
Timers with replaceable batteries are generally not functional after exposure to freezing temperatures for several day, but the non-replaceable type generally have wider tolerance for temperature variation.
Water Heater Timers Save Money