Esraa_92 Esraa_92 - 1 year ago 129 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

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download