PDA

Click to See Complete Forum and Search --> : Month String From Number


richy
Jun 15th, 2001, 07:36 AM
Quick question hopefully,

Is there a keyword that quickly changes the number of the Month into the correct name.
For example 1=January, 2=February?

richy
Jun 20th, 2001, 09:50 AM
Sorry if I missed the most important piece of information out...It's actually for ASP, and MonthName doesn't seem to work in ASP!
Sorry again!

CiberTHuG
Jun 20th, 2001, 11:02 AM
:confused:

MonthName() not only works for me, I'm using it quite liberally.

'Course, I'm on W2K, so what is that, IIS5? Are you on an older server using an older version of VBScript?

Anyway... if you can't use MonthName(), you'll have to use a switched case.

richy
Jun 21st, 2001, 04:47 AM
I've put in the following...



if(thename="bob")then
tmptest=monthname(tmpday)
response.write tmptest & " is the test<BR>" & chr(13)
end if



but it comes up with the following error


Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'monthname'

/intranet/telephone/logcall/logcall.asp, line 72


We're using Windows 2000 with IIS5 so theres nothing wrong there then. Any more ideas anyone?

CiberTHuG
Jun 21st, 2001, 08:28 AM
What is tmpday? If it is a date, you will need to do this...


strMonth = MonthName(Month(myDate))

richy
Jun 21st, 2001, 10:50 AM
tmpday is the number of the month. I've actually got it as tmpmonth so I don't know why I wrote tmpday!
ASP is not finding the function MonthName at all, rather than me putting in faulty values.

CiberTHuG
Jun 21st, 2001, 10:57 AM
If I do this on a page, all by its lonesome, it works.

<%=MonthName(1)%>

I don't know how to check for libraries or such. *shrug* I have IIS 5 on W2K Pro with VS 6 Enterprise.

CMangano
Jun 21st, 2001, 07:25 PM
According to this page:

http://msdn.microsoft.com/scripting/vbscript/doc/vtoriversioninformation.htm

MonthName() was introduced in VBScript 2.0. I am hoping you have a newer version of VBScript then 2.

Have you tried doing <% = MonthName(1) %> as mentioned above?

richy
Jun 22nd, 2001, 03:16 AM
Yep...that worked. So now I must go back to my code to understand why its not working!
Anyone got any ideas...my codes above, but I've now got the line as


tmptest=MonthName(int(tmpday))


because I thought it might be something to do with integers etc.

Cheers for everyones help.

CMangano
Jun 22nd, 2001, 04:32 PM
I did the following code on PWS on NT 4 and got the result January. As you can see, I made tmpMonth equal to the string 1. Using CInt() I changed it to an int and it worked:


tmpMonth = "1"
Response.Write MonthName(CInt(tmpMonth))


On a side note, even when I did not use CInt, it still worked:


tmpMonth = "1"
Response.Write MonthName(tmpMonth)


So you may want to make sure that tmpMonth is indeed equal to 1 by doing a Response.Write.

HTH.

NeoZ018
Jun 22nd, 2001, 08:21 PM
Richy,

Invalid Procedure Call or Argument indicates that you're passing it an invalid argument, as in your tmpMonth is not what you think it is. MonthName will accept a variant for the first argument, meaning MonthName("1"), MonthName(1), MonthName(CLng(1)), MonthName(Int(True) * -1) will all return January (of course the latter is kinda dumb, but it works). There MUST be something wrong with your tmpMonth, I would try MonthName(Month(tmpMonth)) or just Response.Write tmpMonth to see exactly what it is.

Tanner

richy
Jun 25th, 2001, 03:38 AM
Yes indeed, it was my quality code which was passing a blank variable! My apologies and I will now go and sit in the corner with a big dunce hat on!!!