Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Jun 2009
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone know how to output the current date in Spanish in an Access Report, for example "11 de enero de 2010"

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Create a new VBA module, and copy the following function into it:

    Code:
    Function Date2Spanish(d As Variant) As Variant
      Dim m As String
      If Not IsDate(d) Then
        Date2Spanish = Null
      Else
        Select Case Month(d)
          Case 1
            m = "enero"
          Case 2
            m = "febrero"
          Case 3
            m = "marzo"
          Case 4
            m = "abril"
          Case 5
            m = "mayo"
          Case 6
            m = "junio"
          Case 7
            m = "julio"
          Case 8
            m = "agosto"
          Case 9
            m = "septiembre"
          Case 10
            m = "octubre"
          Case 11
            m = "noviembre"
          Case 12
            m = "diciembre"
        End Select
        Date2Spanish = Day(d) & " de " & m & " de " & Year(d)
      End If
    End Function
    You can use it in a calculated column in a query:

    SpanishDate: Date2Spanish([MyDateField])

    and in the control source of a text box on a form or report:

    =Date2Spanish(Date())

    (The first example will format a date field as a Spanish date, the second example will show the current date)

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Do you have the Spanish Language version of Windows. If so you may have some help there, but I suspect it won't format dates that way. You will probably need to create a function to do the formatting in any event. The existing date functions such as Month(), Day() and Year() should let you extract the correct values and in the case of Months you may want to do a join to a table containing the Spanish month names.
    Wendell

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Here's a somewhat more compact version of the function:

    Code:
    Function Date2Spanish(d As Variant) As Variant
      If Not IsDate(d) Then
        Date2Spanish = Null
      Else
        Date2Spanish = Day(d) & " de " & Choose(Month(d), _
          "enero", "febrero", "marzo", "abril", _
          "mayo", "junio", "julio", "agosto", "septiembre", _
          "octubre", "noviembre", "diciembre") & " de " & Year(d)
      End If
    End Function

  5. #5
    Star Lounger
    Join Date
    Jun 2009
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    HansV,

    Once again, a perfect solution. You rock! Just curious, how would I format to display just the current Month, Year, e.g. Enero 2010.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Change

    Code:
        Date2Spanish = Day(d) & " de " & Choose(Month(d), _
          "enero", "febrero", "marzo", "abril", _
          "mayo", "junio", "julio", "agosto", "septiembre", _
          "octubre", "noviembre", "diciembre") & " de " & Year(d)
    to

    Code:
        Date2Spanish = Choose(Month(d), _
          "enero", "febrero", "marzo", "abril", _
          "mayo", "junio", "julio", "agosto", "septiembre", _
          "octubre", "noviembre", "diciembre") & " " & Year(d)

  7. #7
    2 Star Lounger
    Join Date
    Dec 2009
    Location
    Dallas, Texas, USA
    Posts
    113
    Thanks
    3
    Thanked 6 Times in 6 Posts
    Wendall,

    If the computer supports Spanish, even if only as an alternative language, the WinNLS API can be used to extract the month and weekday names for any locale. Of course, this requires calls into the Windows API, either directly or through C wrapper functions. I have the C wrappers to do that, including the ability to return a BSTR (Basic String), but they currently use the user's current language settings. With a few more hours of work, they could easily support any installed locale.
    David Gray, Chief Wizard
    WizardWrx
    Irving, Texas, USA

    WizardWrx Web - Technical Articles and Free Software
    You are more important than any technology we may employ.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •