Programming question: if statement using rtc.getDataStr()

I have an Arduino project and am using a DS3231 RTC. I am using the DS3231.h library.

I wrote the following if statement that was supposed to execute A if today’s date, determined by rtc.getDataStr(), was less than the date “31.05.2019”, otherwise it was to execute B.

if(strcmp(rtc.getDateStr(), "31.05.2019") <= 0) {

Do thing A }

else {

Do thing B }

Since today is 04.06.2019, I expected the if statement above to execute B but instead it executed A. Does anyone know how to correct the problem?

Thank you,
Scott

The problem is that strcmp() compares two strings, not the value of the two strings.

Which DS3231 library are you using ?

Hi UKHeliBob,
Thank you for the reply.
How can I tell which DS3231 library I have installed? (I checked the IDE Library Manager and did a query. Several come up.)
Please advise.
Thank you,
Scott

How can I tell which DS3231 library I have installed?

If you installed it using the Library Manager then if you open it (the Library Manager) and filter the display using 3231 the libraries will be listed. Does one of then indicate that it installed ?

If you did not use the Library Manager there may be an indication of its origin in the .h or .cpp files of the library or a readme file in the DS3231 library folder

Do you remember how you installed it ?

Hi UKHeliBob,
I checked the documentation file and believe the library is from Rinky-Dink.
Scott

It's easier to compare dates using timestamps instead of strings :slight_smile:

All of this was already covered in your Other Thread. The two germane recommendations that you, for some reason, have chosen to ignore are:

  • Don't compare dates using strings (or Strings). Use Epoch-based integer time. Depending on the board (for example, Teensy and AVR are different), this will be either an in32_t or a uint32_t.

  • Dump the Rinky Dink Library and use the Christensen DS3232 Library.

gfvalvo,

Please understand that I am new to the forum. I have trouble sometimes finding posts others have left for me. I do not intentionally chose "to ignore" any comments provided to me for assistance. What sense would that make?

Thank you for your information.

using arduino nano trying to add timer1fast.h to libaray. used google to locate file but unable to add to libaray.
the pwm test compiles just fine but when i try to add libaray timer1fast.h the file will not compile. any suggestions

Stoneking:
using arduino nano trying to add timer1fast.h to libaray. used google to locate file but unable to add to libaray.
the pwm test compiles just fine but when i try to add libaray timer1fast.h the file will not compile. any suggestions

Has your question got anything to do with the thread that you added it to ?