add "st", "nd", "rd", "th" to Date Picker selection

B

Bill

I have a Date Picker Content Control ("Date") which displays the date as "dd
'day of' MMMM, YYYY"

Is there a way for ContentControlOnExit to append the "dd" value to add "st"
"nd" "rd" and "th" as appropriate after the date has been selected?
 
G

Greg Maxey

Assumes the ContentControl title is "Date" ]

Note: The change is not made when the date is selected, but "OnExit" from
the control.



Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel
As Boolean)
If CC.Title = "Date" Then
Dim pStrDay As String
pStrDay = Left(CC.Range.Text, 2)
Select Case pStrDay
Case "01", "21", "31"
pStrDay = "dd'st day of' "
Case "02", "22"
pStrDay = "dd'nd day of' "
Case "03", "23"
pStrDay = "dd'rd day of' "
Case Else
pStrDay = "dd'th day of' "
End Select
CC.DateDisplayFormat = pStrDay & "MMMM yyyy"
End If
End Sub
 
B

Bill

Greg, thanks for your reply several months ago. For the most part your
solution works. There is some imperfection however.

For single digit days (1-9) they are displayed as (01-09). When I modify
the pStrDay from "dd'th" to "d'th" and change the CC.Range.Text, from 2 to 1
that issue is corrected and 1-9 display correctly.
However, I then get the issue of 10-19 displaying as "st", 20-29 displaying
as "nd" and 30-31 displaying as "rd"

How can I have both single digit dates displayed as 1-9 instead of 01-09 and
proper functionality for the rest of the month?

Greg Maxey said:
Assumes the ContentControl title is "Date" ]

Note: The change is not made when the date is selected, but "OnExit" from
the control.



Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel
As Boolean)
If CC.Title = "Date" Then
Dim pStrDay As String
pStrDay = Left(CC.Range.Text, 2)
Select Case pStrDay
Case "01", "21", "31"
pStrDay = "dd'st day of' "
Case "02", "22"
pStrDay = "dd'nd day of' "
Case "03", "23"
pStrDay = "dd'rd day of' "
Case Else
pStrDay = "dd'th day of' "
End Select
CC.DateDisplayFormat = pStrDay & "MMMM yyyy"
End If
End Sub


I have a Date Picker Content Control ("Date") which displays the date
as "dd 'day of' MMMM, YYYY"

Is there a way for ContentControlOnExit to append the "dd" value to
add "st" "nd" "rd" and "th" as appropriate after the date has been
selected?
 
G

Graham Mayor

The following should work

pStrDay = Left(CC.Range.Text, 2)
Select Case pStrDay
Case "01"
pStrDay = "d'st day of' "
Case "21", "31"
pStrDay = "dd'st day of' "
Case "02"
pStrDay = "d'nd day of' "
Case "22"
pStrDay = "dd'nd day of' "
Case "03"
pStrDay = "d'rd day of' "
Case "23"
pStrDay = "dd'rd day of' "
Case "04", "05", "06", "07", "08", "09"
pStrDay = "d'th day of' "
Case Else
pStrDay = "dd'th day of' "
End Select


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Greg, thanks for your reply several months ago. For the most part
your solution works. There is some imperfection however.

For single digit days (1-9) they are displayed as (01-09). When I
modify the pStrDay from "dd'th" to "d'th" and change the
CC.Range.Text, from 2 to 1 that issue is corrected and 1-9 display
correctly.
However, I then get the issue of 10-19 displaying as "st", 20-29
displaying as "nd" and 30-31 displaying as "rd"

How can I have both single digit dates displayed as 1-9 instead of
01-09 and proper functionality for the rest of the month?

Greg Maxey said:
Assumes the ContentControl title is "Date" ]

Note: The change is not made when the date is selected, but
"OnExit" from the control.



Private Sub Document_ContentControlOnExit(ByVal CC As
ContentControl, Cancel As Boolean)
If CC.Title = "Date" Then
Dim pStrDay As String
pStrDay = Left(CC.Range.Text, 2)
Select Case pStrDay
Case "01", "21", "31"
pStrDay = "dd'st day of' "
Case "02", "22"
pStrDay = "dd'nd day of' "
Case "03", "23"
pStrDay = "dd'rd day of' "
Case Else
pStrDay = "dd'th day of' "
End Select
CC.DateDisplayFormat = pStrDay & "MMMM yyyy"
End If
End Sub


I have a Date Picker Content Control ("Date") which displays the
date as "dd 'day of' MMMM, YYYY"

Is there a way for ContentControlOnExit to append the "dd" value to
add "st" "nd" "rd" and "th" as appropriate after the date has been
selected?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top