Esraa_92 Esraa_92 - 2 months ago 12
Vb.net Question

How can I convert MMM format month to MM date in vb.net?

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

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)
Comments