Blog
Dates - How to format date day numbers with suffix (st nd rd th)
July 26. 2023
If you need to format or get the suffix for a day number (eg 1st, 2nd, 3rd), this post describes the formula you can use.
Power Apps provides the ability to format datetime values with the help of the Text function.
This formula extracts the parts of the string. It calls the Switch function on the day number and conditionally returns the suffix for the day number.
How to superscript day suffixes
It's common to format the day suffixes with superscript characters. We can accomplish this by using the Unicode superscript characters (copying and pasting the code block beneath will work).
As shown in the screenshot beneath, the 'th' suffix is now formatted with superscript characters.
The example syntax looks like this:
Text(Now(), "dd-MMM-yyyy hh:mm:ss tt zzz")
There may be a requirement to format day numbers with suffixes but unfortunately, there is no format string character that returns the day suffix.
To work around this issue, we can use the syntax beneath to return the day suffix.
With({inputDate:Now()},
$" {Text(inputDate,"dd")}{Switch(Day(inputDate),
1, "st",
21, "st",
31, "st",
2, "nd",
22, "nd",
3, "rd",
23, "rd",
"th"
)} {Text(inputDate,"mmm yyy")}"
)
This formula extracts the parts of the string. It calls the Switch function on the day number and conditionally returns the suffix for the day number.
Here's a screenshot that shows the result.
How to superscript day suffixes
It's common to format the day suffixes with superscript characters. We can accomplish this by using the Unicode superscript characters (copying and pasting the code block beneath will work). With({inputDate:Now()},
$" {Text(inputDate,"dd")}{Switch(Day(inputDate),
1, "ˢᵗ",
21, "ˢᵗ",
31, "ˢᵗ",
2, "ⁿᵈ",
22, "ⁿᵈ",
3, "ʳᵈ",
23, "ʳᵈ",
"ᵗʰ"
)} {Text(inputDate,"mmm yyy")}"
)
As shown in the screenshot beneath, the 'th' suffix is now formatted with superscript characters.
.
Conclusion
This post described the formula to display the suffix for a day number. It also demonstrated how to display the suffix with superscript characters.
- Categories:
- dates
Related posts
- Dates - How to convert a month name (eg January, Feburary, March) to month number (eg, 1, 2, 3)
- Formula - How to get the dates for the current week
- Dates - How to calculate UK tax weeks
- Dates - How to convert dates from MM DD YYYY to DD MM YYYY and vice versa
- Dates - How to detect overlapping times / scheduling conflicts
- Dates - How to display or convert Excel date serial numbers
- Dates - How to get the start date from week number
- Dates - How to check if a year is a leap year
- Dates - How to get the week number for a given date
- Dates - How to get the nth weekday for a month
- Dates - How to get the last weekday for a month
- Dates - How to get a numbered list of days or months, starting from a specified day or month
- Controls - How to display dates in a combo box
- Search - How to filter records by month and year using a delegable expression