Converting month to numeric

BigJimSlade

Registered User.
Local time
Today, 16:47
Joined
Oct 11, 2000
Messages
173
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
 
You didn't give any details but m in the format property of a control will display the month number, or DatePart etc
 
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
 
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...
 
Last edited:
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
 
Thanks all!

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

Big Jim
 

Users who are viewing this thread

Back
Top Bottom