Sandip's Programming Zen

An attempt to share tech/coding experiences

Retrieve compilation date of a .Net Assembly

leave a comment »

I wanted to display last update date on the application interface so users know when something is changed, mostly at the time of customer acceptance tests. I found following code from here. cool.

private DateTime DateCompiled()
    // The assembly version must have the last two numbers removed and replaced with *
    // It should look something like this: 
    // [assembly: AssemblyVersion("1.0.*")]
    //Build dates start from 01/01/2000
    System.DateTime result = DateTime.Parse("1/1/2000");
    //Retrieve the version information from the assembly from which this code is being executed
    System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
    //Add the number of days (build)
    result = result.AddDays(version.Build);
    //Add the number of seconds since midnight (revision) multiplied by 2
    result = result.AddSeconds(version.Revision * 2);
    //If we're currently in daylight saving time add an extra hour
    if (TimeZone.IsDaylightSavingTime(System.DateTime.Now, 
        result = result.AddHours(1); 
    return result;

Written by Sandip

February 16, 2010 at 11:11 am

Posted in .Net, Asp.Net, Programming

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: