RTC with OLED loses time when switched off

part of example sketch

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

When I originally did the project, I did not program the DS3231. The compiler was happy and everything worked. However because of the clock not remembering the time after it was powered off I assumed the DS3231 needed programming also. So I did that. Ever since I programmed the DS3231 the compiler lists lots of faults, such as the above.
Because of this, if I were to put the current time and date into the IDE to program it, it wont do it, because it now lists lots of faults.
I appreciate your rep[ly Kolaha, and I can now see the format that I set the date and time. I thank you for that.
The compiler wont do it now though.

One solution I can think of is to be able to reprogram the DS3231 to how it was before, in a state of brand new. The other is to order another DS3231 and use that, and see if it then works with a manual time and date set, in the sketch. Which I assume it will.

is used for current time. but IRL it is ~20 seconds after real time due to compiling time.

This is an error that the compiler says

Compilation error: 'DS3231 clock' redeclared as different kind of symbol

I did a 7 segement clock like that ~8 years ago. :grin:

What do you mean when you refer to "programming the DS3231" ? How do you program it and what can you change ?

I programmed the DS3231 with the arduino with a DS3231 sketch.

It was because the clock didnt remember the time when switched off, and I assumed then that the DS3231 needed the DS3231 software to use the lithium battery. Ever since I did that the sketch lists lots of errors.

This is perhaps the main thing that its saying is wrong. I post a compiler error

Compilation error: 'DS3231 clock' redeclared as different kind of symbol

If I hadnt programmed the DS3231 with the DS3231 software, then setting the time and date with the IDE would likely work.
I think if I ordered another DS3231 and used that, it would work.

Nope, hardware like that doesn't contribute to compiler warnings.

Try changing the DS3231 clock; to some other name like DS3231 rtc_clock since there seems to be a name clash.

really?

That seems to have worked! Now the error has changed to

Compilation error: 'RTCDateTime' does not name a type; did you mean 'DateTime'?

OK, but what exactly did you program into it ? I assume that it was the date and time and just possibly some alarms

You seem to have 2 separate problems with your current sketch

  1. every time you run the sketch the date/time is set to the compile time but you only need to do that once. It has been explained how to do this in this topic
  2. You have compilation errors cause by name clashes. Again, the solution has been explained

What? Have you spotted something wrong?

That seems to have worked! Now the error has changed to

Compilation error: 'RTCDateTime' does not name a type; did you mean 'DateTime'?

Something else now needs changing. It is getting there!

yes. change 'RTCDateTime' to 'DateTime'

Comment out this line in the code, I looked at the current library example and it is no longer used and your code doesn't appear to use it either.

Presuming this example was for an old library version.

it is used

You are having problems because the compiler is using the wrong library. You need to find out which library is needed for your code, and remove any other libraries that have a file named "DS3231.h".