Results 1 to 14 of 14
  1. #1
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74

    How to change date of birth into text

    Hi,
    I have this date of birth field on table. For some reasons, I want to convert it into text. For example, 10/05/1978 should be converted into 'Tenth May Nineteen Seventy Eight'. Is there any way I can do this? Any help is truly appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You would never store that in a table.
    You could certainly create a user defined function to do this. You would only ever want to display this "strange format" on a form or report.
    Can you tell us more about the " for some reasons"?

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I have seen need for converting number to words - like on checks but never seen need for date to words. Maybe this is for some sort of formal certificate.

    This might give you idea of what is involved http://support.microsoft.com/kb/213360
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    In addition to the link from June7, this code should get you started. You can work out the Year based on these posts.

    Code:
    Sub DatesToText()
    
        Dim MDate As Date
        Dim suffix As String
        MDate = #5/27/2014#
        Dim Ordinals(31)
        Ordinals(1) = "First"
        Ordinals(2) = "Second"
        Ordinals(3) = "Third"
        Ordinals(4) = "Fourth"
        Ordinals(5) = "Fifth"
        Ordinals(6) = "Sixth"
        Ordinals(7) = "Seventh"
        Ordinals(8) = "Eighth"
        Ordinals(9) = "Nineth"
        Ordinals(10) = "Tenth"
        Ordinals(11) = "Eleventh"
        Ordinals(12) = "Twelfth"
        Ordinals(13) = "Thirteenth"
        Ordinals(14) = "Fourteenth"
        Ordinals(15) = "Fifteenth"
        Ordinals(16) = "Sixteenth"
        Ordinals(17) = "Seventeenth"
        Ordinals(18) = "Eighteenth"
        Ordinals(19) = "Nineteenth"
        Ordinals(20) = "Twentieth"
        Ordinals(21) = "Twentyfirst"
        Ordinals(22) = "Twentysecond"
        Ordinals(23) = "Twentythird"
        Ordinals(24) = "Twentyfourth"
        Ordinals(25) = "Twentyfifth"
        Ordinals(26) = "Twentysixth"
        Ordinals(27) = "Twentyseventh"
        Ordinals(28) = "Twentyeighth"
        Ordinals(29) = "Twentynineth"
        Ordinals(30) = "Thirtieth"
        Ordinals(31) = "Thirtyfirst"
    
        If IsDate(MDate) Then
            Debug.Print Ordinals(Day(MDate)) & " " & MonthName(Month(MDate))
        End If
    
    
    End Sub

  5. #5
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    Quote Originally Posted by orange View Post
    In addition to the link from June7, this code should get you started. You can work out the Year based on these posts.

    Code:
    Sub DatesToText()
    
        Dim MDate As Date
        Dim suffix As String
        MDate = #5/27/2014#
        Dim Ordinals(31)
        Ordinals(1) = "First"
        Ordinals(2) = "Second"
        Ordinals(3) = "Third"
        Ordinals(4) = "Fourth"
        Ordinals(5) = "Fifth"
        Ordinals(6) = "Sixth"
        Ordinals(7) = "Seventh"
        Ordinals(8) = "Eighth"
        Ordinals(9) = "Nineth"
        Ordinals(10) = "Tenth"
        Ordinals(11) = "Eleventh"
        Ordinals(12) = "Twelfth"
        Ordinals(13) = "Thirteenth"
        Ordinals(14) = "Fourteenth"
        Ordinals(15) = "Fifteenth"
        Ordinals(16) = "Sixteenth"
        Ordinals(17) = "Seventeenth"
        Ordinals(18) = "Eighteenth"
        Ordinals(19) = "Nineteenth"
        Ordinals(20) = "Twentieth"
        Ordinals(21) = "Twentyfirst"
        Ordinals(22) = "Twentysecond"
        Ordinals(23) = "Twentythird"
        Ordinals(24) = "Twentyfourth"
        Ordinals(25) = "Twentyfifth"
        Ordinals(26) = "Twentysixth"
        Ordinals(27) = "Twentyseventh"
        Ordinals(28) = "Twentyeighth"
        Ordinals(29) = "Twentynineth"
        Ordinals(30) = "Thirtieth"
        Ordinals(31) = "Thirtyfirst"
    
        If IsDate(MDate) Then
            Debug.Print Ordinals(Day(MDate)) & " " & MonthName(Month(MDate))
        End If
    
    
    End Sub
    That's very kind of you. But I am not very familiar with VB code, so could you please tell me where it should go on the report? Again, I will be grateful if you can show me just one example of the month and the year. Then I can work out the rest. Also, how do I put the three codes (for day, month and year) together?
    Thank you very much.

  6. #6
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    It is for printing a certificate. I don't know whether you do it like this, but in my country (India) we have such weird practices.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The code would go in a VBA custom function procedure. Put code in a general module so it can be available from anywhere in the db. The code would extract each date part to convert to words and concatenate the word strings. Orange's code creates and populates an array for days of month. So something like:

    Function DateToWords(dteDate As Date) As String

    'insert orange's code to populate array for days

    'adapt code from link to convert year part to words, include directly in this procedure or call function

    DateToWords = Ordinals(Day(dteDate)) & " " & Format(dteDate, "mmmm") & " " & SpellNumber(Year(dteDate))

    End Function


    Call the function from textbox ControlSource, like: =DateToWords([datefield])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    Quote Originally Posted by June7 View Post
    The code would go in a VBA custom function procedure. Put code in a general module so it can be available from anywhere in the db. The code would extract each date part to convert to words and concatenate the word strings. Orange's code creates and populates an array for days of month. So something like:

    Function DateToWords(dteDate As Date) As String

    'insert orange's code to populate array for days

    'adapt code from link to convert year part to words, include directly in this procedure or call function

    DateToWords = Ordinals(Day(dteDate)) & " " & Format(dteDate, "mmmm") & " " & SpellNumber(Year(dteDate))

    End Function


    Call the function from textbox ControlSource, like: =DateToWords([datefield])
    Sorry to bother you again, but is it like this:

    Sub DatesToText()

    Dim MDate As Date
    Dim suffix As String
    MDate = #5/27/2014#
    Dim Ordinals(31)
    Ordinals(1) = "First"
    Ordinals(2) = "Second"
    Ordinals(3) = "Third"
    Ordinals(4) = "Fourth"
    Ordinals(5) = "Fifth"
    Ordinals(6) = "Sixth"
    Ordinals(7) = "Seventh"
    Ordinals(8) = "Eighth"
    Ordinals(9) = "Nineth"
    Ordinals(10) = "Tenth"
    Ordinals(11) = "Eleventh"
    Ordinals(12) = "Twelfth"
    Ordinals(13) = "Thirteenth"
    Ordinals(14) = "Fourteenth"
    Ordinals(15) = "Fifteenth"
    Ordinals(16) = "Sixteenth"
    Ordinals(17) = "Seventeenth"
    Ordinals(18) = "Eighteenth"
    Ordinals(19) = "Nineteenth"
    Ordinals(20) = "Twentieth"
    Ordinals(21) = "Twentyfirst"
    Ordinals(22) = "Twentysecond"
    Ordinals(23) = "Twentythird"
    Ordinals(24) = "Twentyfourth"
    Ordinals(25) = "Twentyfifth"
    Ordinals(26) = "Twentysixth"
    Ordinals(27) = "Twentyseventh"
    Ordinals(28) = "Twentyeighth"
    Ordinals(29) = "Twentynineth"
    Ordinals(30) = "Thirtieth"
    Ordinals(31) = "Thirtyfirst"

    If IsDate(MDate) Then
    Debug.Print Ordinals(Day(MDate)) & " " & MonthName(Month(MDate))
    End If


    End Sub

    Dim MDate As Date
    Dim suffix As String
    MDate = #5/27/2014#
    Dim Ordinals(12)
    Month(1) = "January"
    Month(2) = "February"
    Month(3) = "March"
    Month(4) = "April"
    Month(5) = "May"
    Month(6) = "June"
    Month(7) = "July"
    Month(8) = "August"
    Month(9) = "September"
    Month(10) = "October"
    Month(11) = "November"
    Month(12) = "December"

    If IsDate(MDate) Then
    Debug.Print Ordinals(Day(MDate)) & " " & MonthName(Month(MDate))
    End If


    End Sub

    Dim MDate As Date
    Dim suffix As String
    MDate = #5/27/2014#
    Dim Ordinals(31)
    Year(1995) = "Nineteen Ninety Five"
    Year(1996) = "Nineteen Ninety Six"
    Year(1997) = "Nineteen Ninety Seven"
    Year(1998) = "Nineteen Ninety Eight"
    Year(1999) = "Nineteen Ninety Nine"
    Year(2000) = "Two Thousand"

    If IsDate(MDate) Then
    Debug.Print Ordinals(Day(MDate)) & " " & MonthName(Month(MDate))
    End If


    End Sub


    Function DateToWords(dteDate As Date) As String

    'insert orange's code to populate array for days

    'adapt code from link to convert year part to words, include directly in this procedure or call function

    DateToWords = Ordinals(Day(dteDate)) & " " & Format(dteDate, "mmmm") & " " & SpellNumber(Year(dteDate))

    End Function

    Should I write the code like this?Thanks.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    No, that is not what I instructed. Did you try the code you posted? It should error. There are 3 End Sub lines but only one Sub declaration.

    You will be closer if you follow the instructional statements within the function I suggested:

    'insert orange's code to populate array for days

    'adapt code from link to convert year part to words, include directly in this procedure or call function


    An array for months is not necessary. The Format function will extract the month name.

    Could use an array for years instead of the SpellNumber function but your array stops at 2000. Need to build code to handle more years (how far - 2050?) or modify the code every year. If you use an array for the year then it would replace the SpellNumber function call in the concatenation.

    If you use two array objects (one for days and one for years), they need to have different names.

    You might want to learn more about arrays http://office.microsoft.com/en-us/ac...080206268.aspx

    Don't really need the Debug statements. Orange just used that as a way to show the output of suggested code.
    Last edited by June7; 12-28-2014 at 05:25 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    I am really sorry to say that I can't do it... All that I was able to do was to get the month name right. Both day and year failed. It will be a great help for me if you could show me the beginning and ending of the code. And where the following should go:
    Function DateToWords(dteDate As Date) As String

    'insert orange's code to populate array for days

    'adapt code from link to convert year part to words, include directly in this procedure or call function

    DateToWords = Ordinals(Day(dteDate)) & " " & Format(dteDate, "mmmm") & " " & SpellNumber(Year(dteDate))

    End Function

    Does it belong to the same module?

    Will that be asking too much? Many thanks again.

  11. #11
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    May I ask one more thing? Can we do this with three tables- one for day, one for month, and the third for year - each with their own day, month and year strings? Just a thought, that's all.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    All the code should be in the same module. A general module would allow it to be called from anywhere. Here is the function I suggested with my instructions followed:
    Code:
    Function DateToWords(dteDate As Date) As String
    
      'insert orange's code to populate array for days
        Dim Ordinals(31)
        Ordinals(1) = "First"
        Ordinals(2) = "Second"
        Ordinals(3) = "Third"
        Ordinals(4) = "Fourth"
        Ordinals(5) = "Fifth"
        Ordinals(6) = "Sixth"
        Ordinals(7) = "Seventh"
        Ordinals(8) = "Eighth"
        Ordinals(9) = "Nineth"
        Ordinals(10) = "Tenth"
        Ordinals(11) = "Eleventh"
        Ordinals(12) = "Twelfth"
        Ordinals(13) = "Thirteenth"
        Ordinals(14) = "Fourteenth"
        Ordinals(15) = "Fifteenth"
        Ordinals(16) = "Sixteenth"
        Ordinals(17) = "Seventeenth"
        Ordinals(18) = "Eighteenth"
        Ordinals(19) = "Nineteenth"
        Ordinals(20) = "Twentieth"
        Ordinals(21) = "Twentyfirst"
        Ordinals(22) = "Twentysecond"
        Ordinals(23) = "Twentythird"
        Ordinals(24) = "Twentyfourth"
        Ordinals(25) = "Twentyfifth"
        Ordinals(26) = "Twentysixth"
        Ordinals(27) = "Twentyseventh"
        Ordinals(28) = "Twentyeighth"
        Ordinals(29) = "Twentynineth"
        Ordinals(30) = "Thirtieth"
        Ordinals(31) = "Thirtyfirst"
    
      'adapt code from link to convert year part to words, include directly in this procedure or call function
    
      DateToWords = Ordinals(Day(dteDate)) & " " & Format(dteDate, "mmmm") & " " & SpellNumber(Year(dteDate))
    
      End Function
    
    
    'copy/paste code for the 4 functions from the link
    Yes, can use tables as sources for the text values and use DLookup() expressions in textbox and eliminate all VBA.

    =DLookup("DayText", "Days", "DayNum=" & Day([datefield])) & " " & Format(dteDate, "mmmm") & " " & DLookup("YearText", "Years", "YearNum=" & Year([datefield]))

    Or even build queries that join the Days and Years tables to the data table.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    Thanks. Your help and patience is truly appreciated.
    This time I was able to get both day and month right. But not year. Could you please show one example of the code for the year part? I tried several times, but each time it ends with an error.

  14. #14
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74
    Success! Got it at last!
    Many thanks to orange and June7. You've been very helpful.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculate age from Date of Birth
    By djcmalvern in forum Programming
    Replies: 8
    Last Post: 05-03-2013, 06:18 AM
  2. Replies: 3
    Last Post: 06-03-2011, 03:09 PM
  3. Date of birth converter
    By markyboy in forum Forms
    Replies: 1
    Last Post: 05-23-2011, 07:20 AM
  4. Date of Birth Access expression
    By Father John in forum Access
    Replies: 5
    Last Post: 12-02-2010, 10:33 PM
  5. Calculate age from birth date
    By mick in forum Forms
    Replies: 2
    Last Post: 07-03-2010, 04:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums