Created
April 3, 2017 09:44
-
-
Save markwragg/8c24a6462feee7849ba7e06b0b0782fa to your computer and use it in GitHub Desktop.
PowerShell function to add the appropriate ordinal number suffix to an integer for any number and return the number and suffix. Based on: http://stackoverflow.com/questions/19501722/how-to-convert-a-date-string-with-ordinal-suffix-to-another-format
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-OrdinalNumber { | |
Param( | |
[Parameter(Mandatory=$true)] | |
[int64]$num | |
) | |
$Suffix = Switch -regex ($Num) { | |
'1(1|2|3)$' { 'th'; break } | |
'.?1$' { 'st'; break } | |
'.?2$' { 'nd'; break } | |
'.?3$' { 'rd'; break } | |
default { 'th'; break } | |
} | |
Write-Output "$Num$Suffix" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How silly of 2018-me to suggest otherwise ;-)