Format datetime day with st, nd, rd, th

前端 未结 3 544
谎友^
谎友^ 2021-01-24 02:10

I\'m creating a report in SSRS and across the top I have a header with a placeholder for \"Last Refreshed\" which will show when the report last ran.

My function in the

3条回答
  •  梦毁少年i
    2021-01-24 02:45

    Go to layout view. Select Report Properties.Click on the "Code" tab and Enter this code

    Public Function ConvertDate(ByVal mydate As DateTime) as string
      Dim myday as integer
      Dim strsuff As String
      Dim mynewdate As String
      'Default to th
      strsuff = "th" 
      myday = DatePart("d", mydate)
      If myday = 1 Or myday = 21 Or myday = 31 Then strsuff = "st"
      If myday = 2 Or myday = 22 Then strsuff = "nd"
      If myday = 3 Or myday = 23 Then strsuff = "rd"
      mynewdate = CStr(DatePart("d", mydate)) + strsuff + " " +      CStr(MonthName(DatePart("m", mydate))) + " " + CStr(DatePart("yyyy", mydate))
     return mynewdate
    End function
    

    Add the following expression in the required field. I've used a parameter, but you might be referencing a data field?

    =code.ConvertDate(Parameters!Date.Value)
    

提交回复
热议问题