Esraa_92 Esraa_92 - 1 month ago 7x Question

How can I convert MMM format month to MM date in

I need to get the number of the month from an abbreviation:

I have this :

Dim monthname as string = "Jun"

And I need to get this:

Dim monthnumber as integer = 6

How can I get this? thanks


You can use ParseExact to do that:

Dim  monthname as string =  "Jun"
Dim monthNumber as integer = DateTime.ParseExact(monthname , "MMM", CultureInfo.CurrentCulture).Month

Alternatively, create a dictionary:

Dim months = New Dictionary(Of String, Integer) From
{{1, "Jan"}, {2, "Feb"}}, ...

Dim monthNumber = months(monthname)