Counting Date Function

1. Senior Member
Join Date
Dec 1969
Posts
556

## Counting Date Function

Hello, I have a loop that displays dates from records in a database.<BR><BR>What i am trying to do is display the month name for each of the dates that are assigned to that month. eg.<BR><BR>January<BR>05/01/03<BR>15/01/03<BR>21/01/03<BR><BR>Feburary<BR>Febs dates.<BR><BR>I presume I have to make some type of date counter, that checks the month value and then if it a specific value, response.write the name for that value?<BR>

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Counting Date Function

Why...? If the dates are "real" date fields (datetime), then surely it&#039;s a simple "order by" clause....<BR><BR>Isn&#039;t it...?<BR><BR>Craig.

3. Senior Member
Join Date
Dec 1969
Posts
556

## RE: Counting Date Function

Hi Reaper, yes I am ordering the dates already, its just inserting the month name that im stuck with.<BR><BR>Or do you mean do multiple Recordsets/Order by clauses?<BR><BR>Here is my present code.<BR><BR> &#060;%<BR>dbOpen()<BR>set objRS = dbConnect.Execute("SELECT * FROM tblcalendar ORDER BY cid ASC;")<BR>%&#062;<BR>&#060;table width=440 border=0 cellspacing=0 cellpadding=0 align=center height=22&#062;<BR> &#060;tr&#062; <BR> &#060;td width="1" bgcolor="#000000" rowspan="92"&#062;&#060;img src="images/default/blank.gif" width="1" height="1"&#062;&#060;/td&#062;<BR> &#060;td bgcolor="#000000" height="1" colspan="3"&#062;&#060;img src="images/default/blank.gif" width="1" height="1"&#062;&#060;/td&#062;<BR> &#060;td width="1" bgcolor="#000000" rowspan="92"&#062;&#060;img src="images/default/blank.gif" width="1" height="1"&#062;&#060;/td&#062;<BR> &#060;/tr&#062;<BR> &#060;td width=98 class=maintext&#062; &#060;p&#062;&nbsp;&#060;/p&#062;&#060;/td&#062;<BR> &#060;td width=231 class=maintext&#062;&nbsp;&#060;/td&#062;<BR> &#060;td width=105 class=maintext&#062;&nbsp;&#060;/td&#062;<BR>&#060;%<BR>if not objRS.EOF then<BR> do until objRS.EOF <BR>response.write "&#060;tr&#062;" & vbcrlf<BR>response.write "&#060;td width=98 class=maintext&#062;" & vbcrlf<BR>%&#062;<BR>&#060;%<BR>sDate = objrs("cmdate")<BR>eDate = objrs("cmdate2")<BR>days = "" <BR><BR>if ISNULL(eDate) then<BR>response.write "&#060;p&#062;" & sDate & "&#060;/p&#062;" & vbcrlf<BR>else<BR><BR>For i = 0 To DateDiff("D", sDate, eDate) <BR> days = days &" "& DatePart("D",DateAdd("D",i,sDate)) <BR>Next <BR>Response.Write "&#060;p&#062;" & days &" "& DateAdd("D",i,sDate) & "&#060;/p&#062;" & vbcrlf<BR><BR>end if<BR>%&#062;<BR>&#060;%<BR>response.write "&#060;/td&#062;" & vbcrlf<BR>response.write "&#060;td width=231 class=maintext&#062;" & objrs("cmname") & "&#060;/td&#062;" & vbcrlf<BR>response.write "&#060;td width=105 class=maintext&#062;" & objrs("cclub") & "&#060;/td&#062;" & vbcrlf<BR>response.write "&#060;/tr&#062;" & vbcrlf<BR> objRS.Movenext<BR> loop<BR>end if<BR>set objRS = nothing<BR>dbClose()<BR>%&#062;<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Counting Date Function

Ok, it&#039;s way too early for me. What you want is something like this:<BR><BR>&#060;%<BR>Dim strLastMonth<BR>Do while objRS.EOF = False<BR> If MonthName(Month(objRS.Fields("dateField"))) &#060;&#062; strLastMonth Then<BR> strLastMonth = Month(objRS.Fields("dateField"))<BR> Response.Write "&#060;strong&#062;" & strLastMonth & "&#060;/strong&#062;&#060;br /&#062;"<BR> End If<BR> Response.Write objRS.Fields("dateField") & "&#060;br /&#062;"<BR> objRS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>See what&#039;s happening? As you go through, you see if you&#039;ve moved a month. If you HAVE, write out a title...<BR><BR>Craig.

5. Senior Member
Join Date
Dec 1969
Posts
556

## RE: Counting Date Function

Thanks Craig, looks like something I could use. See hwo I go. <BR><BR>Did you just type that up off the top of your head, or did you have it there somewhere?

6. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Counting Date Function

That was off the top of my head. I really should have gone through your code, but the caffine hasn&#039;t really entered my system yet and I can&#039;t get my head around it.<BR><BR>That&#039;s the basic idea of what you&#039;re after. Change the logic to produce exactly what you&#039;re after.<BR><BR>Sometimes it&#039;s better to start again from scratch anyway, once you see the light...!<BR><BR>Craig.

7. Senior Member
Join Date
Dec 1969
Posts
556

## RE: Counting Date Function

How long have you been doing this (vbscript) for craig?

8. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Counting Date Function

ASP? Umm, 3 years...?<BR><BR>Web-based stuff, about 6 or 7. That includes the "old days" where I was doing primarily HTML/JavaScript/DHTML/Perl.<BR><BR>Craig.

#### Posting Permissions

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