How can I include the build date in an executable

I am building a command line app and when the user asks for help with -h or --help I want the help output to include the datetime the executable was built. How can I do this?

Use the same trick as from Include git commit hash as string into Rust program - Stack Overflow

  • println!("cargo:rustc-env=DATE={}", date); in
  • env!("DATE") in or something

Be aware that this will prevent your program from being reproducible. The recommendation is to use the SOURCE_DATE_EPOCH env var if it is set: SOURCE_DATE_EPOCH —


Thanks for your replies. The first one is sufficient for my needs since I don't need reproducible builds.