|
-
Sep 28th, 2010, 05:14 PM
#1
Add compile date to a label
Hi Guys,
I dont think this is possible but thought I would ask anyway just in case...
In several of my apps I have Build Date shown in the Help -> About screen, just so that people can see how recent the version of the app they are using is. I just manually set the text of this label to the current date whenever I compile a new version of the app, but on more than one occasion I have forgotten... so I'm wondering if there is any way I can automate this?
So just to clarify - I do not want today's date (as in the date that the program is being run on), I want to get the date that the program was compiled (either at runtime or compile time, just as long as I dont have to manually enter it) 
Cheers
Chris
-
Sep 28th, 2010, 06:18 PM
#2
Re: Add compile date to a label
Would this work?
Code:
Dim fileTime As String = IO.File.GetLastWriteTime(Application.ExecutablePath).ToString
Or maybe,
Dim MyFileDate As String = IO.File.GetLastWriteTime(Application.ExecutablePath).ToLongDateString
Last edited by Edgemeal; Sep 28th, 2010 at 06:27 PM.
-
Sep 28th, 2010, 06:41 PM
#3
Re: Add compile date to a label
nice trick edgemeal... but would that be affected if the file is copied, or when it's installed?
-tg
-
Sep 28th, 2010, 06:58 PM
#4
Re: Add compile date to a label
have you considered auto-incrementing versions? There is an option to add a .01 or whatever you set to the minor version on each compile.
-
Sep 29th, 2010, 05:39 AM
#5
Re: Add compile date to a label
 Originally Posted by Lord Orwell
have you considered auto-incrementing versions? There is an option to add a .01 or whatever you set to the minor version on each compile.
Well I'm more interested in the date rather than the version number - I do show the version number on my Help -> About screen but I get that dynamically from My.Application.Info.Version.ToString and I always remember to update the version in the Assembly Information section of the project properties whenever I release an update so thats not an issue really.
As for EdgeMetal's suggestion, thanks but I think that going on the last modified date or creation date wouldn't be very reliable because like TG said those dates could get messed up when the program was installed or moved around between machines.
-
Sep 29th, 2010, 12:59 PM
#6
Re: Add compile date to a label
 Originally Posted by chris128
As for EdgeMetal's suggestion, thanks but I think that going on the last modified date or creation date wouldn't be very reliable because like TG said those dates could get messed up when the program was installed or moved around between machines.
Hmmmm, installers shouldn't change a files date, just look at apps installed on your PC, and if I copy a file using VB or Windows that date doesn't change either. But you guys know better then me I guess. Good Luck.
-
Sep 29th, 2010, 01:42 PM
#7
Re: Add compile date to a label
 Originally Posted by chris128
Hi Guys,
I dont think this is possible but thought I would ask anyway just in case...
In several of my apps I have Build Date shown in the Help -> About screen, just so that people can see how recent the version of the app they are using is. I just manually set the text of this label to the current date whenever I compile a new version of the app, but on more than one occasion I have forgotten... so I'm wondering if there is any way I can automate this?
So just to clarify - I do not want today's date (as in the date that the program is being run on), I want to get the date that the program was compiled (either at runtime or compile time, just as long as I dont have to manually enter it)
Cheers
Chris
I haven't actually tried it, but this article explains how to accomplish this via the embedded linker timestamp from the IMAGE_FILE_HEADER section of the Portable Executable header. This article was made 5 years ago, but it's worth a shot 
VB.NET Code:
Function RetrieveLinkerTimestamp(ByVal filePath As String) As DateTime
Const PeHeaderOffset As Integer = 60
Const LinkerTimestampOffset As Integer = 8
Dim b(2047) As Byte
Dim s As Stream
Try
s = New FileStream(filePath, FileMode.Open, FileAccess.Read)
s.Read(b, 0, 2048)
Finally
If Not s Is Nothing Then s.Close()
End Try
Dim i As Integer = BitConverter.ToInt32(b, PeHeaderOffset)
Dim SecondsSince1970 As Integer = BitConverter.ToInt32(b, i + LinkerTimestampOffset)
Dim dt As New DateTime(1970, 1, 1, 0, 0, 0)
dt = dt.AddSeconds(SecondsSince1970)
dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours)
Return dt
End Function
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Sep 29th, 2010, 03:15 PM
#8
Re: Add compile date to a label
Wow thanks that looks like exactly what I want - will give it a go and let you know the results
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|