Converting dates into text

ddennis

New Member
Joined
Apr 21, 2004
Messages
22
Dear all:

I have created a form for diploma printing purposes. I have created a date field in this format: 6/4/2004.

I wish to display the date in another field, but in this format: the fourth day of june two thousand four.

I am not much of a VB wizard, so any help is greatly appreciated.

Dion :oops:
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi Dion,
you'll need to do this --
1. Create a table called tblLookup with an ID field (AutoNumber), InValue (Number) and OutValue (Text). The ID field is the Primary Key. Sample data is
tblLookup.xls
ABCD
1LookupIDInValueOutValue
211First
322Second
433Third
544Fourth
655Fifth
7
82323Twenty-Third
92424Twenty-Fourth
102525Twenty-Fifth
112626Twenty-Sixth
122727Twenty-Seventh
132828Twenty-Eighth
142929Twenty-Ninth
153030Thirtieth
163131Thirty-First
17322003TwoThousandandThree
18332004TwoThousandandFour
19342005TwoThousandandFive
20352006TwoThousandandSix
21362007TwoThousandandSeven
22372008TwoThousandandEight
23382009TwoThousandandNine
24392010TwoThousandandTen
tblLookup

2. Place this code into a new module and call the module basDateFunctions:
Code:
Function WordyDate(TheDate As Date) As String
  Dim TheDay As String
  Dim TheMonth As String
  Dim TheYear As String
  Dim MonthArray(1 To 12) As Variant
  Dim i As Integer, j As Integer, k As Integer
  
  MonthArray(1) = "January"
  MonthArray(2) = "February"
  MonthArray(3) = "March"
  MonthArray(4) = "April"
  MonthArray(5) = "May"
  MonthArray(6) = "June"
  MonthArray(7) = "July"
  MonthArray(8) = "August"
  MonthArray(9) = "September"
  MonthArray(10) = "October"
  MonthArray(11) = "November"
  MonthArray(12) = "December"
  
  i = Month(TheDate)
  TheMonth = MonthArray(i)
  j = Day(TheDate)
  TheDay = DLookup("[OutValue]", "tblLookup", "[Invalue]=" & j)
  k = Year(TheDate)
  TheYear = DLookup("[OutValue]", "tblLookup", "[Invalue]=" & k)

  WordyDate = "The " & TheDay & " Day of " & TheMonth & ", " & TheYear
End Function
3. To use, create a calculated field in a query. Use an expression like PrintDate: WordyDate(dDate) where dDate is the name of the date field that you want to express in words. Output is:
qryWordy.xls
ABCD
1dDateFullNamePrintDate
230-Jul-04BugsBunnyTheThirtiethDayofJuly,TwoThousandandFour
312-Jun-04DaffyDuckTheTwelfthDayofJune,TwoThousandandFour
qryWordy

You can adjust the text to suit what you need. It will do valid dates to 2010, at which time you can add more rows to the tblLookUp table.

Denis
 
Upvote 0
Denis

Looks good

One thing though why not use

TheMonth = Format(TheDate, "mmmm")

to get the month.
 
Upvote 0
Hi Norie,

thanks for the suggestion -- that would be an improvement. I've been doing a lot with arrays recently so that was my first thought :)

Denis
 
Upvote 0
Denis

For years I used to do exactly what you did and I frequently used the Format function but it was only recently I found out about this.
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,938
Members
451,730
Latest member
BudgetGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top