Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VisualStudio: translating a build version to a calendar date

I know that the version string generated by Visual Studio is based on the date/time of when the build was run. Given the partial version string "3856.24352" generated by Visual Studio, how can I translate that to the calendar day on which that build took place?

like image 347
anthony Avatar asked Oct 20 '10 22:10

anthony


2 Answers

The full version string is in the format major.minor.build.revision. The build part is the number of days since 1st January, 2000. The revision part is the number of seconds since midnight divided by 2 (see here for more info).

Assuming that your version strings are the auto-incrementing type, and that you have taken the build.revision part, you can turn it back into the date using:

string buildRevision = "3856.24352";

string[] parts = buildRevision.Split('.');
int build = int.Parse(parts[0]);
int revision = int.Parse(parts[1]);

DateTime dateTimeOfBuild = new DateTime(2000, 1, 1) 
                                + new TimeSpan(build, 0, 0, 0) 
                                + TimeSpan.FromSeconds(revision * 2);

This will give you a DateTime representing when the build was produced (which for your example is 23rd July, 2010 at 13:31:44).

like image 115
adrianbanks Avatar answered Nov 12 '22 10:11

adrianbanks


Here is a simple javascript tool for converting .Net version into a date:

Sample Input:
1.0.7769.27451

Sample Output:
5/9/2021, 3:15:02 PM

function convertBuildNumberToDate()
{
  var buildString = document.getElementById("input").value.split(".");
  var buildNumber = Number(buildString[2]);
  var revision = Number(buildString[3]);

  var date = new Date(2000, 1, 1);
  date.setDate(buildNumber);
  date.setSeconds(revision * 2);

  var output = date.toLocaleString();
  document.getElementById("output").innerHTML = output;
}
Build Number:
<br />
<input id="input" value="1.0.7769.27451" />
<button onclick="convertBuildNumberToDate()">Convert</button>

<br />
<br />

Build Date:
<br />
<div id="output"></div>
like image 2
Maui Avatar answered Nov 12 '22 08:11

Maui