Date related Question

VKPP
VKPP used Ask the Experts™
on
Hi

In VB any funtion is available for getting month value for month name. For example if i give "May" , I should get the month value as 5.

January = 1
Feb = 2........ like that.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
Try:

myMonth = "May"
MsgBox Month(CDate("1 " & myMonth & " " & Year(Date)))

Commented:
use the function Format
 like
 if IsDate(MyMonth) then
 Msgbox Format(MyMonth,"MM")
End IF

Commented:
oups! sorry u should before convert the string to date by CDate function.

Dim MyMonth as String

MyMonth = "january"

Msgbox Format(CDate(MyMonth),"MM")

good luck
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
oups! sorry u should before convert the string to date by CDate function.

Dim MyMonth as String

MyMonth = "january"

Msgbox Format(CDate(MyMonth),"MM")

good luck

Author

Commented:
Hi Chimist

"CDate(MyMonth)" -  its giving run-time error 13 (Type Mismatch).

Commented:
hi,
ok it's just a simple probem i think

so, in the first u should step by step this code :
1- verifie if the value of MyMonth si "january"
2 - Verifie that the function CDate work correctly.
3 - the function Format.

your code will be:

Dim MyMonth as String
Dim MonthVal as Date

 MyMonth = "january"
   debug.Print MyMonth  'To see the value in run window
 MonthVAl = CDate(MyMonth)
    debug.Print MonthVal  'to see if the function CDate work correctly
    Debug.Print  Format (MonthVal, "MM")  'to see if the function Format work correctly



Ryan ChongSoftware Team Lead

Commented:
Tried mine, VKPP ? It's that working?

Author

Commented:
I think ryancys's answer is the only way.

Thanks ryancys !

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial