Retrieve sketch build date and time from bin file

Hello,

Is there a possibility to retrieve compilation/build time of Arduino sketch or export file with this value in filename?

I'm trying to build OTA update service based on sketch compilation time.
Manual retrieve this parameter and adding to file name is pain in the ass.

It would be cool, to upload sketch and webserver will workout automatically what is compilation time of the file, based on it's content or filename.

DATE et TIME are replaced automatically by the preprocessor by the date and time at compile time. If you uploaded right after, it's pretty close to the upload time. This is used for setting up the clock in RTC operations, you'll often see something like

  if (! rtc.initialized()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
   }

So,your code can know when it was compiled and it could ping an update server providing that info and server side you can compare to the file creation date of the latest binary in your repository to decide if you need an update

I'm not asking about retrieving DATE and TIME in sketch. I know how it works.

I'm asking about retrieving this data form compilation, to know when .bin file was compiled (what values of compilation date and time are compiled in file). Either from file data or at compilation process.

Create or mod date often do not retrieve right times (usually 1-3 sec. after compilation time).

I'm asking about retrieving this data form compilation, to know when .bin file was compiled (what values of compilation date and time are compiled in file). Either from file data or at compilation process.

Unless you do something to embed the date and time in the file, the date and time are not there!

Serial.print(DATE) is one way to embed the date in the file, although that doesn't allow you to get at it later.

char *date = DATE;
is another way that DOES allow you to get at the stored date.

I'm sure you can figure out the time equivalent.

ProgWeb:
I'm not asking about retrieving DATE and TIME in sketch. I know how it works.

I'm asking about retrieving this data form compilation, to know when .bin file was compiled (what values of compilation date and time are compiled in file). Either from file data or at compilation process.

Create or mod date often do not retrieve right times (usually 1-3 sec. after compilation time).

and can you explain how 1 to 3 second changes something? and what do you call "compile time"? is that compile, linking, building the final binary for upload?