Display Months

# Thread: Display Months

1. Senior Member
Join Date
Dec 1969
Posts
196

## Display Months

Does anyone know how I can display on a web page, the current month and the previous 4 months?<BR><BR>I am using this code to display the current month:<BR><BR>thismonth = Month(now)<BR>Response.Write MonthName(thismonth)<BR><BR>but how could I then calculate the last 4 months and display those month names? I am wanting to create a feature where users can see information published for the last 4 months etc.<BR><BR>Any ideas?

2. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## RE: Display Months

Dim dt<BR> dt = Date()<BR><BR>Dim cnt<BR><BR>Dim mth<BR><BR> For cnt = 0 To 4<BR> mth = DateAdd("m", dt, cnt * -1)<BR> Response.Write MonthName(mth)<BR> Next<BR><BR>That work?

3. Senior Member
Join Date
Dec 1969
Posts
1,024

## RE: Display Months

&#060;%<BR>for i = 0 to 4<BR> thismonth = Month(now) - i<BR> Response.Write MonthName(thismonth) & "&#060;br /&#062;"<BR>next<BR>%&#062;<BR><BR>?<BR><BR>cp

4. Senior Member
Join Date
Dec 1969
Posts
196

## RE: Display Months

That produces the following error:<BR><BR>Invalid procedure call or argument: &#039;MonthName&#039;

5. Senior Member
Join Date
Dec 1969
Posts
1,024

## close enough.....

blah....<BR><BR><BR>haha<BR>c

6. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## MonthName(-1) ? (eop)

.

7. Senior Member
Join Date
Dec 1969
Posts
1,024

## what? <eop>

8. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Whoops.

Need to put the month into the mth variable - not the date:<BR>Dim dt <BR> dt = Date() <BR><BR>Dim cnt <BR><BR>Dim mth <BR><BR> For cnt = 0 To 4 <BR> mth = Month(DateAdd("m", cnt * -1, dt))<BR> Response.Write MonthName(mth) <BR> Next

9. Senior Member
Join Date
Dec 1969
Posts
196

## RE: Display Months

Yep, that works, thanks...<BR><BR>Problem is now, I need to search date fields in SQL Server 2K in order to pick out all documents that were published in a particular month etc. and display them under the relevant month... Any ideas for doing this?

10. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Assume it's Feb 1.

You&#039;d get:<BR>2<BR>1<BR>0<BR>-1<BR>-2<BR><BR>No?

#### Posting Permissions

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