Skip to content

Instantly share code, notes, and snippets.

@xv
Created May 2, 2026 21:03
Show Gist options
  • Select an option

  • Save xv/e7c625f21752bbba2a41af7a2af374ba to your computer and use it in GitHub Desktop.

Select an option

Save xv/e7c625f21752bbba2a41af7a2af374ba to your computer and use it in GitHub Desktop.
Better (subjective?) C/C++ __DATE__ (Mmm dd yyyy) macro that adds a zero to dd instead of the default space if the value is less than 10.
#define BUILD_DATE (const char[]) { \
__DATE__[0], __DATE__[1], __DATE__[2], __DATE__[3], \
(__DATE__[4] == ' ' ? '0' : __DATE__[4]), __DATE__[5], \
__DATE__[6], __DATE__[7], __DATE__[8], \
__DATE__[9], __DATE__[10], '\0' \
}
// Use:
// printf("%s\n", BUILD_DATE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment