__DATE was not declared in this scope.

I got an error where it says date is not declared in this scope. My friend runs the exact same code and it works for him. Anyone got any idea?

#include <Wire.h>
#include "RTClib.h"  // Credit: Adafruit

RTC_DS1307 RTC;

void setup() {
 
  // Begin the Serial connection 
  Serial.begin(9600);
 
  // Instantiate the RTC
  Wire.begin();
  RTC.begin();
 
  // Check if the RTC is running.
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running");
  }

  // This section grabs the current datetime and compares it to
  // the compilation time.  If necessary, the RTC is updated.
  DateTime now = RTC.now();
  DateTime compiled = DateTime(__DATE, TIME__);
  if (now.unixtime() < compiled.unixtime()) {
    Serial.println("RTC is older than compile time! Updating");
    RTC.adjust(DateTime(__DATE, TIME__));
  }
  Serial.println("Setup complete.");
}

void loop() {
  // Get the current time
  DateTime now = RTC.now();   
 
  // Display the current time
  Serial.print("Current time: ");
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
 
  delay(10000);
}

That should be DATE and TIME (two underscores leading and trailing on both).

stowite:
That should be DATE and TIME (two underscores leading and trailing on both).

This does not work :frowning:

Which version of the IDE?

septillion:
Which version of the IDE?

1.6.11

kingchakir:
This does not work :frowning:

Works for me! I use it to timestamp my compilations and I print it out each time my Arduino starts. You are not expecting it to give the runtime time and date are you?

You should take a look at Standard Predefined Macros (The C Preprocessor)