Using external realtime clock module like this:
http://www.ebay.com/itm/221583720092
through I2C interface, you can have clock running with power off, in addition, there are external EEPROM you can store value into it.
We have a discussion thread showing all the PLC code on this forum in the past.