Last active
June 20, 2020 03:53
-
-
Save vexx32/6716c9995c56f58c264c0b7428c478e0 to your computer and use it in GitHub Desktop.
for Mark Kraus ♥
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-Age { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory)] | |
[ValidateScript( | |
{ | |
$_ -lt [datetimeoffset]::UtcNow | |
} | |
)] | |
[datetimeoffset] | |
$Birthday | |
) | |
# Make it UTC if it ain't | |
$Birthday = $Birthday.ToOffset(0) | |
$current = [datetimeoffset]::UtcNow | |
$Years = $current.Year - $Birthday.Year | |
$Months = $current.Month - $Birthday.Month | |
$Days = $current.Day - $BirthDay.Day | |
$Hours = $current.Hour - $Birthday.Hour | |
$Minutes = $current.Minute - $Birthday.Minute | |
do { | |
if ($Months -lt 0) { | |
$Years-- | |
$Months += 12 | |
} | |
if ($Days -lt 0) { | |
$Months-- | |
$Days += 30 | |
} | |
if ($Hours -lt 0) { | |
$Days-- | |
$Hours += 24 | |
} | |
if ($Minutes -lt 0) { | |
$Hours-- | |
$Minutes += 60 | |
} | |
} while ($Months, $Days, $Hours, $Minutes -lt 0) | |
[PSCustomObject]@{ | |
Years = $Years | |
Months = $Months | |
Days = $Days | |
Hours = $Hours | |
Minutes = $Minutes | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment