ANSI-C provides two macros:
__DATE__
__TIME__
which can be used for this. They get replaced by the compiler with the actual data and time.
I'm using this in my own firmware like this:
byte CLS1_PrintStatus(CLS1_ConstStdIOType *io)
{
CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
CLS1_SendStr((unsigned char*)CLS1_DASH_LINE, io->stdOut);
CLS1_SendStr((unsigned char*)"\r\nSYSTEM STATUS\r\n", io->stdOut);
CLS1_SendStr((unsigned char*)CLS1_DASH_LINE, io->stdOut);
CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
CLS1_SendStatusStr((const unsigned char*)"Firmware", (const unsigned char*)__DATE__, io->stdOut);
CLS1_SendStr((unsigned char*)" ", io->stdOut);
CLS1_SendStr((unsigned char*)__TIME__, io->stdOut);
CLS1_SendStr((unsigned char*)"\r\n", io->stdOut);
return ERR_OK;
}
You can see an example output of this in this blog post (last screenshot):
A Shell for the Freedom KL25Z Board
I hope this helps.