Results 1 to 5 of 5

Thread: MonthName function

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    9

    MonthName function

    hi

    i stored some dates in ms acces, and i'm using visual studio 6.0, visual basic 6.0

    i used this sql statement to get the monthnumber out of the dates, stored as short date type.

    month([cd.datum]) as maand.

    this works

    now i want to get the monthname out of the monthnumber
    and i tried this

    MonthName(month([cd.datum]),true) as maandnaam

    Probably i'll get a syntax error too, but now i only get the following message

    'expression contains an undefined function MonthName'

    According to msdn.com,this function should be defined in vb 6.0 !


    Do i have to update my visualstudio ?
    where can i find those updates?
    is my syntax right? (i want the monthname, abreviated = true)

    thx
    grtz,
    w.

  2. #2
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: MonthName function

    You can get this with the Format function, but it would probably be easiest to retrieve the entire date, and then picking out the parts you need to manipulate. Here are a couple of examples:

    VB Code:
    1. Dim iMonth As Integer
    2. Dim sDate as String
    3.  
    4. iMonth = 7                                                'July, for example
    5. sDate = "01/14/2005"
    6.  
    7. sMonth = Format(sDate, "mmmm")                            'Full name
    8. sMonth = Format(sDate, "mmm")                             'Short name
    9. sMonth = Format(DateAdd("M", iMonth, 0), "mmmm")          'Month only

    The first two work with a full date string (date type too), and the last one will return the name of an enumerated month.

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: MonthName function

    Something like this may work for you:
    VB Code:
    1. Private Sub Command2_Click()
    2. Dim intMonth%
    3.  
    4.     intMonth = Month(Now)
    5.     MsgBox Format(intMonth & "/" & Day(Now) & "/" & Year(Now), "mmmm")
    6.  
    7. End Sub

  4. #4
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: MonthName function

    Quote Originally Posted by RhinoBull
    Something like this may work for you:
    VB Code:
    1. Private Sub Command2_Click()
    2. Dim intMonth%
    3.  
    4.     intMonth = Month(Now)
    5.     MsgBox Format(intMonth & "/" & Day(Now) & "/" & Year(Now), "mmmm")
    6.  
    7. End Sub
    This would be dependant on the system's international date setting, whereas this is not:

    VB Code:
    1. MsgBox (Format(DateAdd("M", Month(Now), 0), "mmm"))

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: MonthName function

    Quote Originally Posted by Comintern
    This would be dependant on the system's international date setting ...
    That's why I said "something like ..."

Posting Permissions

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



Click Here to Expand Forum to Full Width