date function

1. Senior Member
Join Date
Dec 1969
Posts
556

## date function

Hey all, I have a problm with this function. I set 2 dates.<BR>1st a beginning date. 2nd a ending date. <BR>I am trying to write the dates from the beginning to the end date.<BR><BR>The function below works however I always get an extra date on the end.<BR><BR>So I I had a start sate of 12/12/03 and end date of 14/12/03 It will write.<BR>12, 13, 14, 15 /12/03<BR><BR>Can someone show me wha tI am doing wrong.<BR><BR>sDate = objrs("cmdate")<BR>eDate = objrs("cmdate2")<BR>days = "" <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

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

What&#039;s the DateDiff("D",#12/12/03#,#14/12/03#)???<BR><BR>I make it as 2, don&#039;t you?<BR><BR>So now you do (simplifying that overly complex code)<BR> For i = 0 To 2<BR> Response.Write sDate+i<BR> Next<BR> Response.Write sdate+i<BR><BR>So if sDate is 12/12/03, then your loop will do<BR> i=0: 12/12/03<BR> i=1: 13/12/03<BR> i=2: 14/12/03<BR>and the line after the loop will do<BR> i=3: 15/12/03<BR><BR>WHY are you making it so complex???<BR><BR>Why not simply do:<BR><BR>&#060;%<BR>sDate = objrs("cmdate")<BR>eDate = objrs("cmdate2")<BR><BR>For dt = sDate To eDate<BR> If dt &#060;&#062; sDate Then Response.Write ","<BR> Response.Write dt<BR>Next <BR>%&#062;<BR>

3. Senior Member
Join Date
Dec 1969
Posts
556

## Im too much of a right side thinker.

Hi Bill I do tend to overcomplicate things when they dont need complicating.<BR><BR>This is what I ended up doing.<BR><BR>For dt = sDate To eDate <BR> If dt &#060;&#062; sDate Then Response.Write "," <BR> Response.Write day(dt) <BR>if dt = eDate then Response.write "/" & Month(eDate) & "/" & Year(eDate)<BR>Next <BR>end if<BR><BR>which the end results is<BR>eg: sd - 12/12/2003 ed - 14/12/2003<BR><BR>12,13,14/12/2003<BR><BR>Thanks again for the help.

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