Convert Month name to integer value
Posted: 12/10/2004 3:19:31 PMBy: Comfortably Anonymous
Times Read: 2,413
Likes: 0 Dislikes: 0
Topic: Programming: .NET Framework
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
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)
Discussion View:
By: Comfortably Anonymous
Times Read: 2,413
Likes: 0 Dislikes: 0
Topic: Programming: .NET Framework
Replies:
Convert Month name to integer value
Posted: 12/10/2004 3:19:31 PMBy: Comfortably Anonymous
Times Read: 2,413
Likes: 0 Dislikes: 0
Topic: Programming: .NET Framework
Why not use the following function:
MonthNo = Month("January 01, 2006")
Returns 1
MonthNo = Month("Jul 31, 2006")
Returns 7
MonthNo = Month("SEP 01, 2006")
Returns 9
MonthNo = Month("January 01, 2006")
Returns 1
MonthNo = Month("Jul 31, 2006")
Returns 7
MonthNo = Month("SEP 01, 2006")
Returns 9
Rating: (You must be logged in to vote)