View Light

Convert Month name to integer value

OK, unlike the last thread, I have not found a built-in function which does the opposite (such as: return 2 when passed a string containing "February" or return 7 when passed "July"), so here is the code for that (Formatting is terrible here, but when you cut from here and paste into Visual Studio, it will format and indent it correctly...)

Private Function MonthToInt(ByVal month As String) As Integer
' Could use some tuning to ignore casing and to handle abbreviations

        Select Case month
            Case "January"
                Return 1
            Case "February"
                Return 2
            Case "March"
                Return 3
            Case "April"
                Return 4
            Case "May"
                Return 5
            Case "June"
                Return 6
            Case "July"
                Return 7
            Case "August"
                Return 8
            Case "September"
                Return 9
            Case "October"
                Return 10
            Case "November"
                Return 11
            Case "December"
                Return 12
        End Select
    End Function
Rating: (You must be logged in to vote)
Comfortably Anonymous
7/21/2006 9:32:44 AM
0 Dislikes: 0
Comfortably Anonymous
7/26/2006 9:57:02 PM
0 Dislikes: 0
This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit to those who have expressed a prior interest in receiving the included information for research and educational purposes. For more information go to: . If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.