View Full Version : Converting month to numeric


BigJimSlade
07-24-2002, 06:10 PM
Hey, Big Jim here:

I was searching for this one in Access help, but I could not find it...

What function would I use to convert "January" to "1"?

Thanks in advance!

Big Jim

Rich
07-24-2002, 08:38 PM
You didn't give any details but m in the format property of a control will display the month number, or DatePart etc

BigJimSlade
07-24-2002, 08:47 PM
Hmmm, details....

Well, I have a string with a value of "January"

I would like to write some code that will convert "January" to "1" in a new string.

In other words:

strMonthName = "January"
strMonthNumeric = Format(strMonthName,"m") ' which sets strMonthNumeric to "1"

That is the idea, but the above just returns "January" so it seems.

Thanks for your help!

Big Jim

DALeffler
07-24-2002, 09:43 PM
You need to give the month function something to work with:

Dim strng As String
Dim dmmy As String

strng = "January"
dmmy = ",1 ,2000"
strng = LTrim(Str(Month(strng & dmmy)))

strng is now "1"...

Doug.

Edited: added LTrim...

raskew
07-25-2002, 03:30 AM
You could also use the DateValue function in your scenario:
(1)
smon = "August"
? ltrim(str(month(datevalue(smon & "/01"))))
8

or
(2)
Function sMon(strMon As String) As String
Dim varMon As Variant
varMon = DateValue(strMon & "/02")
sMon = LTrim(Str(Month(varMon)))
End Function

? sMon("March")
3

BigJimSlade
07-25-2002, 08:17 PM
Thanks all!

I appreciate the help, looks like it will work great!

Big Jim