Skip to content

Instantly share code, notes, and snippets.

@jozefizso
Created December 11, 2015 21:23
Show Gist options
  • Save jozefizso/2162d1ac5f8a120b0e51 to your computer and use it in GitHub Desktop.
Save jozefizso/2162d1ac5f8a120b0e51 to your computer and use it in GitHub Desktop.
PowerShell build number functions

PowerShell build number functions

Based on algorithm from Visual Studio for generating the major and minor parts of the build number.

Major build number 0.0.X.0 is number of days since January 1st, 2000. Minor build number (the revision component 0.0.0.Y) is number of seconds since midnight divided by 2.

function Get-DevMajorBuildNumber($now = (Get-Date)) {
$baseDate = [datetime]"2000-01-01T00:00:00.000Z"
$ts = New-Timespan -Start $baseDate -End $now
[int][Math]::Floor($ts.TotalDays)
}
function Get-DevMinorBuildNumber($now = (Get-Date)) {
$baseDate = Get-Date -Year $now.Year -Month $now.Month -Day $now.Day -Hour 0 -Minute 0 -Second 0
$ts = New-Timespan -Start $baseDate -End $now
[int][Math]::Floor($ts.TotalSeconds/2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment