Combining Text and Date Vaules

G

Guest

I’m using the following expression with a date field. For a date of 01/01/05
it returns “This 1 day of January, 2005.†How can I get it to return "This
1st day..." (or 2nd day, 3rd day, etc.)?

LegalDate: "This " & Format([OrderDate],"d") & " day of " &
Format([OrderDate],"mmmm") & ", " & Format([OrderDate],"yyyy") & "."
 
D

Douglas J. Steele

You'll have to write your own function, along the lines of:

Function OrdinalDate(ValueIn As Long) As String

Select Case ValueIn
Case 1, 21, 31
OrdinalDate = ValueIn & "st"
Case 2, 22
OrdinalDate = ValueIn & "nd"
Case 3, 23
OrdinalDate = ValueIn & "rd"
Case Else
OrdinalDate = ValueIn & "th"
End Select

End Function

Change your query to

LegalDate: "This " & OrdinalDate(DatePart("d", [OrderDate])) & " day of " &
Format([OrderDate],"mmmm") & ", " & Format([OrderDate],"yyyy") & "."
 
J

John Vinson

I’m using the following expression with a date field. For a date of 01/01/05
it returns “This 1 day of January, 2005.” How can I get it to return "This
1st day..." (or 2nd day, 3rd day, etc.)?

LegalDate: "This " & Format([OrderDate],"d") & " day of " &
Format([OrderDate],"mmmm") & ", " & Format([OrderDate],"yyyy") & "."

I think you'll need a Switch() statement:

LegalDate: "This " & Format([OrderDate],"d") &
Switch(
Right(Format([OrderDate], "d"), 1) = 1, "st",
Right(Format([OrderDate], "d"), 1) = 2, "nd",
Right(Format([OrderDate], "d"), 1) = 3, "rd",
True, "th") &
" day of " &
Format([OrderDate],"mmmm") & ", " & Format([OrderDate],"yyyy") & "."

John W. Vinson[MVP]
 
D

Douglas J. Steele

John Vinson said:
I'm using the following expression with a date field. For a date of
01/01/05
it returns "This 1 day of January, 2005." How can I get it to return
"This
1st day..." (or 2nd day, 3rd day, etc.)?

LegalDate: "This " & Format([OrderDate],"d") & " day of " &
Format([OrderDate],"mmmm") & ", " & Format([OrderDate],"yyyy") & "."

I think you'll need a Switch() statement:

LegalDate: "This " & Format([OrderDate],"d") &
Switch(
Right(Format([OrderDate], "d"), 1) = 1, "st",
Right(Format([OrderDate], "d"), 1) = 2, "nd",
Right(Format([OrderDate], "d"), 1) = 3, "rd",
True, "th") &
" day of " &
Format([OrderDate],"mmmm") & ", " & Format([OrderDate],"yyyy") & "."

Won't that give you "This 11st day of ..."?
 

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

Similar Threads

Combining Text and Date Values 2
Modifying Date Range 3
Modifying Date Range 2 2
Dlookup 7
DateDiff Question 4
Subtract 1 Year from Query Date Range 9
mailmarge date format in word 1
date format 3

Top