Retrieve date when application was flashed to a device?


Is there a way to retrieve the date when an application was flashed onto a certain device (Photon) and read that as a Particle.variable()???


@Jan_dM, I put this code in all my devices. It reports the application name, the date and time it was compiled and flashed and the DeviceOS version on the device, all accessible via the Particle.variable() deviceInfo.

// This strips the path from the filename
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

char gDeviceInfo[120];  //adjust size as required

void setup()

    snprintf(gDeviceInfo, sizeof(gDeviceInfo)
        ,"App: %s, Date: %s, Time: %s, Sysver: %s"
        ,(const char*)System.version()  // cast required for String



Thank you peekay123!
This works fine.


great idea.
I use something similar on Arduino:

  Serial.begin(115200);       // set up Serial library at 9600 bps
  String compiledtime = "";   // I have to use compiledtime because 'complied' is already used for RTC stuff
  String filenm = "";
  filenm = __FILE__ ;

  compiledtime = __DATE__ ;
  compiledtime = compiledtime + " " + __TIME__ ;
  Serial.print("Complied at ");


Just a note about performance and memory facilitation of this approach: Creating several intermediate String variables merely for holding and concatenating string literals that are already defined isn’t necessary nor good practice :wink:

  Serial.println("Compiled at " __DATE__ " " __TIME__);

will do the same thing without dynamic memory allocation and intermediate assignments.
In case you really needed a variable compiledtime this would be the alternative approach.

const char* compiledtime = __DATE__ " " __TIME__;


Thanks ScruffR, good point.