I have a report requirement where I have to print a date formatted like the 15th day of June… Does anyone have an easy way to do this?
thanks
I have a report requirement where I have to print a date formatted like the 15th day of June… Does anyone have an easy way to do this?
thanks
Only in English?
for Win or MacOS?
I don’t have the whole piece of code, but I have enough pieces to put a method together for you… easy peasy
actually… I have code to do it based on locale if you’d rather…
English only but both Mac and PC…
Dim day As Integer=dt.day
dim postfix as string
Dim strMth As String=NthField("January|February|March|April|May|June|July|August|September|October|November|December","|",dt.Month)
Select Case day
Case 1,21,31
postfix="st"
Case 2,22
postfix="nd"
Case 3,23
postfix="rd"
Case 4 To 20,24 To 30
postfix="th"
End Select
Return Str(day)+postfix+" day of "+strmth
Public Function OrdinalSuffix(n As Integer) as string
static suffix() As string = array("th","st","nd","rd","th")
dim i As Integer = n mod 100
if i>20 then i=i mod 10
return suffix(min(4,i))
End Function
Thanks Dave, and Robert. But I like Dave’s solution for being simple, clear and “Self-documenting”. thanks again.
Understood. I’ll just point out that the function I posted will return the correct ordinal suffix for any integer. It’s not limited to numbers 1 to 31.