Combining Text and Date Vaules

  • Thread starter Thread starter Guest
  • Start date Start date
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") & "."
 
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") & "."
 
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]
 
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 ..."?
 
Won't that give you "This 11st day of ..."?

Oops! Yes indeed.

Your solution is obviously preferable (in that it will work).

John W. Vinson[MVP]
 

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
Dlookup 7
mailmarge date format in word 1
Stored date is not being recognised 1
date format 3
Access 2007 and Dates 1
Dates from Text 4
Problem formatting dates from CSV file 2

Back
Top