Oct 20, 2015

Add the Compile Time and Date to your C++ or Arduino source code

To include the compile date or time in your program (as a way to keep track of versions), I discovered that there are compiler constant strings for this in Arduino's compiler.

To include in your arduino code, use these lines near the top of your program.
// get date and time of compile...           
char compileDATE[] PROGMEM = __DATE__;
char compileTIME[] PROGMEM = __TIME__;  
Then, to use it in your program, include the array in a print statement.

Serial.println(compileTIME);

prints:   20:38:56

Or, in a formatted print string using printf(),

compileDATE[3] = '.';  // replace spaces
compileDATE[6] = '.';

Serial.printf("Date %s  Time %s", compileDATE, compileTIME);

prints:   Date Oct.20.2015  Time 20:38:56