Recent

Author Topic: add date/time to an executable when compiling and use it as a version constant  (Read 2880 times)

RickD

  • New Member
  • *
  • Posts: 14
Hello everybody,

I'm looking for a way to add the current date and time to an executable when it compiles, so i can use it as a version constant string to show after the program is compiled.

Does anybody know if it is possible to do such a thing, and if so how?

Regards,
Rick

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Code: [Select]
    BuildDate := {$I %DATE%};  // y/m/d format
    FpcVersion := 'FPC ' + {$I %FPCVERSION%};

Bart

Phil

  • Hero Member
  • *****
  • Posts: 2737
I'm looking for a way to add the current date and time to an executable when it compiles, so i can use it as a version constant string to show after the program is compiled.

Bart's solution will work for what you require, although you won't be able to distinguish between multiple builds on the same day. If that's an issue, use %TIME% as well.

A more conventional approach to versioning is to enable the versioning resource in Project Options on the Version Info tab. And also check the box labeled "Automatically increase build number". That means the last part of the version will increment by one with each build. Now you have a way of distinguishing between builds that also has the advantage of being visible outside your program, whereas your approach is limited to your app's UI.

For example, if in Windows Explorer you right click on your executable and choose Properties, you'll see your executable's version info settings.

Although a version info resource is a Windows feature, you can use some of these project settings on other platforms too.
See the Lazarus Cross-Platform Project article here for details on how to do that:

https://macpgmr.github.io/

For example, on OS X, if you select an .app in Finder and enter Cmd+I, you'll see some of the project settings.

 

TinyPortal © 2005-2018