mistux Site Admin
Joined: 25 Jun 2004 Posts: 1042 Location: South Bend, Indiana USA
|
Posted: Wed Sep 26, 2007 12:33 pm Post subject: Convert Month names to short form abreviations and others |
|
|
Here are some samples to deal with converting months names to numbers.
Code: |
Public Function getMonthNum(MonthName As String) As Integer
Dim retVal As Integer
Select Case MonthName
Case "January", "Jan"
retVal = 1
Case "February", "Feb"
retVal = 2
Case "March", "Mar"
retVal = 3
Case "April", "Apr"
retVal = 4
Case "May"
retVal = 5
Case "June", "Jun"
retVal = 6
Case "July", "Jul"
retVal = 7
Case "August", "Aug"
retVal = 8
Case "September", "Sep", "Sept"
retVal = 9
Case "October", "Oct"
retVal = 10
Case "November", "Nov"
retVal = 11
Case "December", "Dec"
retVal = 12
End Select
getMonthNum = retVal
End Function |
And
Code: |
Assume your month is coming from a text box on a form...
Dim strMonth As String
Dim intMonth As Integer
strMonth = Me.txtMonth
intMonth = Month(1 & " " & strMonth)
|
Code: |
Function GetMonthInt (strMonth as String) as Integer
GetMonthInt = Month(1 & " " & strMonth)
End Function
Then you can call it in a piece of code by using...
Dim intMonth as integer
intMonth = GetMonthInt(Me.txtMonth)
or edit the parameter to use it in a query.
|
|
|