News

AssemblyAttribute explained–Part 2

2012-05-29 10:25:55 by Kjell-Åke Gafvelin

There has been some interest in my blog post AssemblyAttribute explained regarding how build numbers are calculated from the date when the application was compiled. So I thought I could also make a post on how to calculate the date from the build number.

So if you have set the AssemblyVersionAttribute in your application to the following:

   1:  [assembly: AssemblyVersion("1.0.*")]

you could calculate the date from the build number using the following code snippet:

   1:              Version version = Assembly.GetExecutingAssembly().GetName().Version;
   2:   
   3:              DateTime date = new DateTime(2000, 1, 1);
   4:   
   5:              date = date.AddDays(version.Build);
   6:   
   7:              date = date.AddSeconds(version.Revision * 2);
   8:   
   9:              if (date.IsDaylightSavingTime())
  10:                  date = date.Add(TimeZone.CurrentTimeZone.GetDaylightChanges(date.Year).Delta);
  11:   
  12:              Console.WriteLine(version.ToString() + " => " + date.ToString());

This code snipped would output this:

1.0.4532.14997 => 2012-05-29 09:19:54

|