There has been some interest in my blog post about AssemblyVersionAttribute 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:
[assembly: AssemblyVersion("1.0.*")]
you could calculate the date from the build number using the following code snippet:
Version version = Assembly.GetExecutingAssembly().GetName().Version;
DateTime date = new DateTime(2000, 1, 1);
date = date.AddDays(version.Build);
date = date.AddSeconds(version.Revision * 2);
if (date.IsDaylightSavingTime())
{
date = date.Add(TimeZone.CurrentTimeZone.GetDaylightChanges(date.Year).Delta);
}
Console.WriteLine(version.ToString() + " => " + date.ToString());
This code snippet would output this:
1.0.4532.14997 => 2012-05-29 09:19:54