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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Dim MyMonth as String
MyMonth = "january"
Msgbox Format(CDate(MyMonth),"MM"
good luck
ASKER
Hi Chimist
"CDate(MyMonth)" - its giving run-time error 13 (Type Mismatch).
"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
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?
ASKER
I think ryancys's answer is the only way.
Thanks ryancys !
Thanks ryancys !
like
if IsDate(MyMonth) then
Msgbox Format(MyMonth,"MM")
End IF