DelphiFAQ Home Search:

How to get the compile Date into the executable


comments11 comments. Current rating: 3 stars (8 votes). Leave comments and/ or rate it.

It's very nice to have a number say in the about box that the customer can read you, and you can immediately find the version.

Write a program which outputs the current date to a text file called something like '' and include it with {$include} in each of your units.
Then integrate this little tool into your Delphi IDE and run it every time you make a new build.

// by Martin Larsson,
// include file ""
   _day   : string[10] = 'Monday';
   _date  : word = 12;
   _month : word = 8;
   _year  : word = 1996;


2007-01-29, 19:38:08
anonymous from Korea (R)  
'Then integrate this little tool into your Delphi IDE and run it every time you make a new build.'

Running that little tool manually isn't a matter. But is there a way to run it automatically before building?
2008-02-06, 19:07:40
anonymous from Hong Kong  
well, I don't see any post or pre build events in my Delphi 7 contrary to VS2005. Am I missing something or this is just wishfull thinking.
2008-03-20, 16:01:04 from South Africa  
An easier and neater way is to use the compiled project exe file date. In VB .NET 2003 this is easily done with

Inports System.IO

dim strDate as string
dim fName as string

fName = Application.StartupPath & '\YourProjectFilename.exe'

strDate= File.GetLastWriteTime(fName)

2008-04-17, 19:44:12 from Australia  
I would not suggest using the last write time if you are depending on the version for things such as database restructuring, (i.e., if you're using version 20080401 but the exe says it's version 20080418). The reason for this is that your executable's 'Date Modified' can be altered fairly easily, and as such does not represent the actual compilation date always.

That being said, it will work most of the time, and it is a fairly neat way.

The first suggestion is probably better, basically having a const hard coded to a date and/or time stamp.
2009-07-05, 00:47:45  
...That being said, it will work most of the time, and it is a fairly neat way.

I agree, but here's what I'm doing. (Thanks for the idea!) Use an .ini file to *store* the CompileDate every time that you compile&run. When the About uses the 'CompileDate' variable, it will be accurate to the minute of the last compile & run. Be sure to include the .ini file in the initial distribution and updates.

tempStr : string;
tempDate : tdatetime;


myIniFile := TIniFile.Create('MyName.ini'); // gen and/or open the .ini

// get the timestamp
TempStr := path + name + '.dproj';
if FileAge(TempStr, tempDate) = true then // get the true compile date
MyIniFile.WriteFloat ('Defaults', 'CompileDate', tempDate);

(results found in the ini file)

(when reading the .ini)
strCompileDate := FloatToStr(MyIniFile.Readfloat('Defaults', 'CompileDate',0.0));

Yes, since 'FileAge' as a single variable syntax is deprecated. I'm using the newer overloaded version that sets a Tdatetime variable. Nice.

In fini... it is unfortunate that using a second file (ini) for updates, will LOSE the true date if only the exe is distributed. GACK! I'm afraid that 'updates' (newer compiledates) may require a non-visible label with the 'release date' MANUALLY embedded. Now...if only I knew how to change a label.caption and have it SAVED when I save the form. Any help there?
2009-08-04, 11:44:59
[hidden] from Longmont, United States  
Per my previous message, I did learn how to embed the compile date into a form.

Add a blank form to your project. I called it 'Compile_Date'. After the first compile you'll also have a Compile_Date.DFM which is something you can modify *BEFORE* you do...
Application.CreateForm(TCompile_date, Compile_date); {in your main.DFM}

So, in the CreateForm event for the MAIN form, you can include the following, which will automatically update the 'Compile_date.DFM' only while you are running it in your development environment. (FileExists)

procedure TmainForm.formcreate(Sender: TObject);
slVersion : tstringlist;
i : integer;
Version : string = 'Compile_Date.DFM';
slVersion := tstringlist.create;
if FileExists(Version) = true then
for i := 0 to slVersion.Count - 1 do
if pos('Caption',slVersion[i]) > 0 then
SLVersion[i] := 'Caption = ''' + DateTimeToStr(now) + '' ;

Bottom line: its an easy solution, but I'll go one better. The folks at Embarcadero (Delphi) now have a TCompile Unit!!! It has MUCH more than just a compile date. :)

The unit file 'Project.pas' contains the following constants:
PROJECT_NAME: The name of the project.
EXE_FILENAME: The file name of the project.
DATE_CREATED: The date that the project was originally created.
AUTHORS_NAME: The name of the people who wrote the code for the project.
CONTACT_INFO: Contact information: eMail, phone number, address, etc.
COMPILE_DATE: Date project last ran inside Delphi.
COMPILE_TIME: Time project last ran inside Delphi.
BUILD_NUMBER: Number of times the project has been ran from inside Delphi.
UNIQUE_IDKEY: Unique identifier for the project. It has the ProjectName, CompileDate and CompileTime. NOTE: This constant is updated every compile to reflect the current compile date and time.


The only negative I can see is that you need to also embed your project path. So, don't move the puppy!


2020-06-23, 23:57:56
Enriqueta from United States  
Greetings from Florida! I'm bored to death at work so I
decided to browse your blog on my iphone during lunch break.

I enjoy the knowledge you provide here and can't wait to take a look when I get home.

I'm shocked at how quick your blog loaded on my cell phone ..
I'm not even using WIFI, just 3G .. Anyhow, fantastic
2020-06-26, 03:59:58
naltrexone prices
2020-07-03, 09:45:26
amoxicillin for cats without a vet
2020-07-04, 11:54:50
cost of cephalexin
2020-07-06, 07:09:13
Sharyl from Germany  
does viagra have generic judpharmacy



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: