Weird RTC DS3231 Output only when saving the dates to variables I am sorry to ask this question as I think it has more to do with my mediocre C++ programming skill than with the arduino.
I do have a project where I want to use an RTC DS2131. I started out by using all the separate examples of the modules I need and put them together. But the RTC give me a headache :-(
The example ran fine where it just output the date to the serial port. Somthing along this:
Serial.print(RTC.getDay());
Serial.print(&quot;-&quot;);
Serial.print(RTC.getMonth());

Now I want these values in different variables because I want to save them on an SD card as well.
Thus I came up with this simple test program:
#include &lt;Wire.h&gt;
#include &lt;RTC.h&gt;

static DS3231 RTC;

void setup()
{ 
  Serial.begin(9600);
  RTC.begin();
}

void loop()
{  
int yearNow; 
int monthNow, dateNow, hourNow, minuteNow, secondNow, weekNow;

if (RTC.isRunning())
  {
    yearNow=RTC.getYear();
    monthNow =RTC.getMonth();
    dateNow=RTC.getDay();
    weekNow=RTC.getWeek();
    hourNow=RTC.getHours();
    minuteNow=RTC.getMinutes();
    secondNow=RTC.getSeconds();
   
    Serial.print(&quot;Weekday: &quot;);
    Serial.print(weekNow);
    Serial.print('  Time:');
    // Finally the hour, minute, and second
    Serial.print(hourNow);
    Serial.print('-');
    Serial.print(minuteNow);
    Serial.print('-');
    Serial.print(secondNow);
    Serial.print(&quot; ##  &quot;);    
    Serial.print(&quot;Date: &quot;);
    Serial.print(yearNow);
    Serial.print('/');
    Serial.print(monthNow);
    Serial.print('/');
    Serial.println(dateNow);
    
  }
}

Now I would expect this output:
Weekday: 4  Time:16-10-36 ##  Date: 2020/7/28
But this is what I get:
Weekday: 42591416-10-36 ##  Date: 2020/7/28
As a sidenote the variables in this sketch are declared as &quot;int&quot;. After having looked into the header files of the library I tried uint8_t resp. uint16_t for the year.
But nothing changed.
I am sorry but I have no clue as what beginner mistake I am achieving this time?? :-(
Thanks for your help.
You used single quotes instead of double quotes. Single quotes are for single characters. Double quotes are for strings (or character arrays).
Serial.print('  Time:');

should be
Serial.print(&quot;  Time:&quot;);