ASP Date question

1. Junior Member
Join Date
Dec 1969
Posts
27

## ASP Date question

I checked the faq and search engines on this and came up with nothing. I need to return a number(i.e. 1,2,3) of the month based on the name of the month(i.e. March,April). I&#039;m sure it is a common thing but I cannot seem to track it down.<BR>Thanks,<BR>kibb

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## Err, Month()?

Built in VBS function. Though January will be 0.. make sure you add a 1 if you need to.

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## Cute! No intrinsic way, but...

Here are two solutions.<BR><BR>The straightforward one:<BR><BR>&#060;%<BR>theMonthName = ...<BR><BR>For m = 1 To 12<BR>&nbsp; &nbsp; If MonthName(m) = theMonthName Then Exit For<BR>Next<BR><BR>&#039; when you get here, m is the matching month...m will be 13 if no match<BR>...<BR>%&#062;<BR><BR>But here&#039;s a sneakier way:<BR><BR>&#060;%<BR>theMonthName = ...<BR><BR>temp = CDate( theMonthName & " 1, 2002" )<BR>monthNum = Month(temp)<BR>%&#062;<BR><BR>See the trick? We make VBS create a valid Date variant for us for the 1st of that month (in any year). Then we can easily extract the month.<BR><BR>You can do it all in one line:<BR><BR>&#060;%<BR>theMonthName = ...<BR><BR>monthNum = Month( CDate( theMonthName & " 1, 2002" ) )<BR>%&#062;<BR>

4. Junior Member
Join Date
Dec 1969
Posts
27

## RE: Err, Month()?

But I need to make String "January" into number 0, not just the present month&#039;s number.

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Ummm...buggy...

Not true about January being 0. In VBS, January *is* 1. It&#039;s JavaScript where January is 0.<BR><BR>Have you *tried* doing <BR>&nbsp; &nbsp; Month("March") <BR>to see if it works?<BR><BR>If it does, great! If not, see my hack.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Where did you get the idea...

...that Month (and Year and Day and Hour and ...) referred to the *current* date/time? Instead of whatever argument they are given?<BR><BR>

7. Junior Member
Join Date
Dec 1969
Posts
27

## RE: Cute! No intrinsic way, but...

That&#039;s the stuff!<BR>Thanks Bill.

8. Junior Member
Join Date
Dec 1969
Posts
27

## RE: Ummm...buggy...

Ya tried that before I hit the MB.No go, but your hack works. Thanks again.

9. Senior Member
Join Date
Dec 1969
Posts
11,334

## Wait a sec...

Yeah, JS starts it at one. I told you, I language switch so much anymore I can&#039;t remember which is which.<BR><BR>Does VBS support enums? I&#039;ve done this in C:<BR><BR> enum monthname = {January, February, March,<BR> April, May, June, July,<BR> August, September, October,<BR> November, December};<BR><BR><BR>Does that work in VBS? Yeah, yeah, I&#039;m too lazy to try it myself :)

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## Are you overly tired tonight?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsobjdate.asp<BR><BR>Look down to what it says about "month" on that page.<BR><BR>If January is 1 and month has a range of 0 to 11 in JS, then what is month 0???<BR><BR>******************<BR><BR>Enums: No, none of the languages Java, JavaScript, or VBScript support enums. I would also point out that, even in C/C++, all you get from that are *NUMBERS* 0 to 11, with no way to convert from the string "March" to the number 2. Meaning that an enum would be worthless in solving this problem, even in C/C++.<BR><BR>What JavaScript and VBScript *do* have are easy to initialize arrays:<BR><BR>JS: var months = new Array("January","February","March",...);<BR>VBS: months = Array("January","February","March",...)<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•