Skip to content

Instantly share code, notes, and snippets.

@SidShetye
Created December 9, 2016 00:28
Show Gist options
  • Save SidShetye/4aaf1172dfa3128b6d62078e25159b04 to your computer and use it in GitHub Desktop.
Save SidShetye/4aaf1172dfa3128b6d62078e25159b04 to your computer and use it in GitHub Desktop.
In .NET builds auto-increment if your code specified build versions like "1.2.*". This powershell script goes the reverse and helps find the date of release given a version number
Param(
[Version] $Version ="1.2.5678.6432"
)
# Usage as 'Get-BuildDateFromVersion.ps1 -Version 1.2.3.4'
# Intentionally written in verbose mode, line by line
# From https://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx and
# http://stackoverflow.com/questions/13943456/what-is-the-formula-in-net-for-wildcard-version-numbers
# Build = DateTime.Today.Subtract(new DateTime(2000, 1, 1)).Days;
# Revision = (int)DateTime.Now.Subtract(DateTime.Today).TotalSeconds / 2;
# Start at epoc
$date = New-Object System.DateTime 2000,1,1
# Add days (build)
$date = $date.AddDays($Version.Build)
# Add seconds x 2
$date = $date.AddSeconds($Version.Revision * 2)
Write-Host "Build time: " $date.ToString("F")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment