Search code examples
sqlvb.netsql-server-2008rdlcdate-format

How to append th, st, nd and rd for dates of the day in rdlc report?


I'm working with certifications and I need to append date of the day suffixes. I tried using =Day(Fields!Date.value) in the expression property of the TextBox but the output is just a number/date of the day but has no suffix. I have no problem in Month and Year only the suffixes in the date of the day. Thanks


Solution

  • Using the suggestion in Is there an easy way to create ordinals in C#? you can create a Custom Code for your rdlc report and use it with the expression.

    1. In the rdlc properties add the following function in Code tab

      Public Shared Function AddOrdinal(num As Integer) As String
          If num <= 0 Then
              Return num.ToString()
          End If
          Select Case num Mod 100
              Case 11, 12, 13
                  Return num & "th"
          End Select
          Select Case num Mod 10
              Case 1
                  Return num & "st"
              Case 2
                  Return num & "nd"
              Case 3
                  Return num & "rd"
              Case Else
                  Return num & "th"
          End Select
      End Function
      
    2. Then modify your Expression as follows

      =Code.AddOrdinal(Day(Fields!Date.value))