How to convert date in words?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mangeshsava
    New Member
    • May 2012
    • 1

    How to convert date in words?

    I want to convert date like 1-1-2011 covert "First January, Two thousand eleven". What is code for module in Access?
  • Mihail
    Contributor
    • Apr 2011
    • 759

    #2
    A possible solution:

    Code:
    Option Compare Database
    Option Explicit
    
    Sub Test()
    Dim TestDate As Date
        TestDate = CDate("11.04.2013")
    Dim dtString As String
        dtString = DateInWords(TestDate)
        
        MsgBox (dtString)
    End Sub
    
    Function DateInWords(dt As Date) As String
    Dim strDays As String, SplitDays
        strDays = "Day_1,Day_2,Day_3,Day_4,Day_5,Day_6,Day_7,Day_8,Day_9,Day_10,Day_11,Day_12,Day_13,Day_14,Day_15,Day_16,Day_17,Day_18,Day_19,Day_20,Day_21,Day_22,Day_23,Day_24,Day_25,Day_26,Day_27,Day_28,Day_29,Day_30,Day_31"
        SplitDays = Split(strDays, ",")
    Dim strMothes As String, SplitMonthes
        strMothes = "Month_1,Month_2,Month_3,Month_4,Month_5,Month_6,Month_7,Month_8,Month_9,Month_10,Month_11,Month_12"
        SplitMonthes = Split(strMothes, ",")
    Dim strYears As String, SplitYears
        strYears = "Year_2010,Year_2011,Year_2012,Year_2013,Year_2014,Year_2015,Year_2016,Year_2017,Year_2018,Year_2019,Year_2020"
        SplitYears = Split(strYears, ",")
        
    Dim strDay As String
        strDay = SplitDays(Day(dt) - 1)
    Dim strMonth As String
        strMonth = SplitMonthes(Month(dt) - 1)
    Dim strYear As String
        strYear = SplitYears(Year(dt) - 2010)
                    
        DateInWords = strDay & " " & strMonth & ", " & strYear
    End Function

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      Code:
      Format({DateValue},"d mmmm, yyyy")
      This doesn't handle ordinals (First, second, etc), but simply shows the number instead.

      Comment

      Working...