Hello @MCU1536
assuming you are using Arduino and the M5StamPLC library then it is clear as to why the date and time are not retained. There is no code in the M5StamPLC library to enable charging the RTC backup battery.
I created a PR which enables RTC backup battery charging.
Thanks
Felix