Using ‘th’ in Dates How to Format Day Numbers with Suffixes in Power Apps

Using ‘th’ in Dates: How to Format Day Numbers with Suffixes in Power Apps

 

Using ‘th’ in Dates: How to Format Day Numbers with Suffixes in Power Apps

When dealing with dates, it’s often essential to format day numbers with their corresponding suffixes, like 1st, 2nd, and 3rd. However, many platforms, including Power Apps, don’t provide a direct method for this. In this guide, we will walk you through an efficient formula to address this limitation. And remember, if you get stuck or need further technical assistance, feel free to contact us. We’re here to help and guide you through any technical challenges you might face.

The Challenge: Day Number Suffixes in Power Apps

Power Apps has a potent toolset for working with dates via the Text function. A standard example of formatting datetime values in Power Apps is:


Text(CurrentTime(), "dd-MMM-yyyy hh:mm:ss tt zzz")
    

Although useful, a limitation arises when we need to include day number suffixes. No format string character directly returns these suffixes in Power Apps. However, there’s a workaround.

Extracting Day Suffixes: The Solution

Here’s a formula to derive the correct day suffix for any given day:


With({dateValue:CurrentTime()},
$" {Text(dateValue,"dd")}{Switch(Day(dateValue),
    1, "st",
    21, "st",
    31, "st",
    2,  "nd",
    22, "nd",
    3, "rd",
    23, "rd",
    "th"
)} {Text(dateValue,"mmm yyy")}"
)
    

Reference: With function

This formula cleverly breaks down the parts of the date and employs the Switch function to return the appropriate suffix based on the day number.

How to Use Superscript for Day Suffixes

For a polished look, many prefer to display day suffixes in superscript format. Here’s how you can achieve this using Unicode superscript characters in Power Apps:


With({dateValue:CurrentTime()},
$" {Text(dateValue,"dd")}{Switch(Day(dateValue),
    1, "ˢᵗ",
    21, "ˢᵗ",
    31, "ˢᵗ",
    2,  "ⁿᵈ",
    22, "ⁿᵈ",
    3, "ʳᵈ",
    23, "ʳᵈ",
    "ᵗʰ"
)} {Text(dateValue,"mmm yyy")}"
)
    

With this formula, the ‘th’ suffix, for example, is seamlessly formatted in superscript.

Conclusion

Formatting day numbers with suffixes might seem trivial, but it can greatly enhance the user experience and readability of your Power Apps solutions. We’ve explored a straightforward method to add these suffixes, even presenting them in an elegant superscript format. Should you need further insights into Power Apps or any other technical guidance, please don’t hesitate to reach out to us. Our team at SoftwareZone365 is always ready to assist, ensuring you get the best out of your applications.

Enhanced Support Widget