Link to home
Start Free TrialLog in
Avatar of VKPP
VKPP

asked on

Date related Question

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.

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chimist
chimist

use the function Format
 like
 if IsDate(MyMonth) then
 Msgbox Format(MyMonth,"MM")
End IF
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
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
Avatar of VKPP

ASKER

Hi Chimist

"CDate(MyMonth)" -  its giving run-time error 13 (Type Mismatch).
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



Tried mine, VKPP ? It's that working?
Avatar of VKPP

ASKER

I think ryancys's answer is the only way.

Thanks ryancys !