Skip to content

Instantly share code, notes, and snippets.

@markwragg
Created April 3, 2017 09:44
Show Gist options
  • Save markwragg/8c24a6462feee7849ba7e06b0b0782fa to your computer and use it in GitHub Desktop.
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
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"
}
@tonypags
Copy link

How silly of 2018-me to suggest otherwise ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment