Get-MyAge.ps1
<#PSScriptInfo .VERSION 1.0 .GUID 72e37320-04fb-4df9-9ba1-815108578691 .AUTHOR saw-friendship .COMPANYNAME .COPYRIGHT saw-friendship .TAGS saw-friendship My Age .LICENSEURI .PROJECTURI https://sawfriendship.wordpress.com/ .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Measure your Age .LINK https://sawfriendship.wordpress.com/ .EXAMPLE Get-MyAge 1969.06.30 #> param( [datetime]$WasBorn = (Get-Date).AddYears(-18).Date, [datetime]$ToDay = (Get-Date).Date ) if(($ToDay - $WasBorn).TotalDays -lt 365){0;break} Foreach ($Year in ($WasBorn.Year .. $ToDay.Year)) { $BirthDay = $WasBorn | Get-Date -Year $Year if($BirthDay -le $ToDay){ $BirthDays += @($BirthDay) } } [pscustomobject][ordered]@{ 'ToDay' = $ToDay.ToString('yyyy-MM-dd') 'FullYears' = [int]$($BirthDays.Count - 1) 'Age' = [string]$("$($BirthDays.Count - 1) Y & $( ($ToDay - $BirthDays[-1]).TotalDays ) d") 'FirstBirthDay' = $WasBorn.ToString('yyyy-MM-dd') 'FirstBirthDayOfWeek' = $WasBorn.DayOfWeek 'LastBirthDay' = $BirthDays[-1].ToString('yyyy-MM-dd') 'LastBirthDayOfWeek' = $BirthDays[-1].DayOfWeek 'NextBirthDay' = $BirthDays[-1].AddYears(1).ToString('yyyy-MM-dd') 'NextBirthDayOfWeek' = $BirthDays[-1].AddYears(1).DayOfWeek 'NextBirthDaysRemaining' = [int]$(($BirthDays[-1].AddYears(1) - $ToDay).TotalDays) } |