Results 1 to 8 of 8

Thread: Add compile date to a label

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Add compile date to a label

    Quote Originally Posted by Lord Orwell View Post
    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Add compile date to a label

    Quote Originally Posted by chris128 View Post
    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.

  7. #7
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Add compile date to a label

    Quote Originally Posted by chris128 View Post
    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:
    1. Function RetrieveLinkerTimestamp(ByVal filePath As String) As DateTime
    2.   Const PeHeaderOffset As Integer = 60
    3.   Const LinkerTimestampOffset As Integer = 8
    4.  
    5.   Dim b(2047) As Byte
    6.   Dim s As Stream
    7.   Try
    8.     s = New FileStream(filePath, FileMode.Open, FileAccess.Read)
    9.     s.Read(b, 0, 2048)
    10.   Finally
    11.     If Not s Is Nothing Then s.Close()
    12.   End Try
    13.  
    14.   Dim i As Integer = BitConverter.ToInt32(b, PeHeaderOffset)
    15.  
    16.   Dim SecondsSince1970 As Integer = BitConverter.ToInt32(b, i + LinkerTimestampOffset)
    17.   Dim dt As New DateTime(1970, 1, 1, 0, 0, 0)
    18.   dt = dt.AddSeconds(SecondsSince1970)
    19.   dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours)
    20.   Return dt
    21. End Function
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  8. #8

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width