Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting month name to integer 1

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
Is there a date function that converts a month to integer just like strMonth = MonthName (2, True) will translate to Feb.

I'd like to convert Feb back to 2.
 
Well there is the Month() function which I believe returns a number from 0 to 11 ... but I think it requires input of a a date variable, or something that can be converted into a date...


So, suppose you have "Feb" in a string variable named strMonth, maybe you could do something like:
iMonth = Month(strMonth & " 1, 2005") + 1

This is just from memory so I'm not certain here.
 
Well I don't know what language I was thinking of but I just looked it up and the VB Month() function returns 1 - 12 so no need for the +1 in my previous example.
 
strMonth = "Feb"
iMonth = Month(DateValue("01-" & strMonth & "2005"))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV

you forgot a dash

Month(DateValue("01-" & strMonth & "-2005"))

apparently you are not that flawless... ;-)

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Good catch, K0b3
As you know, nobody is perfect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top