Custom Function: Get Number Suffix

Posted in Custom Functions by Dempsey
.

Here is a useful custom function to return the suffix for a day in a month, for example if you pass it 1, it will return st, which you can append to make up a text representation of a date, eg 1st May etc.

Function Name: NumberSuffix
Function Parameters: Number
Function Code

Let( [
special_th = Case(
Mod (Number; 100) = 11 or
Mod (Number; 100) = 12 or
Mod (Number; 100) = 13; 1) ;
end = Mod ( Number ; 10 )
];
Case ( special_th; “th”; end = 1; “st”; end = 2; “nd”; end = 3; “rd”; “th”)
)

Example Input: 22
Example Output: nd
Example Usage: $suffix = NumberSuffx(22)

Leave a Reply