order dates

Results 1 to 2 of 2

Thread: order dates

  1. #1
    Join Date
    Dec 1969

    Default order dates

    Now I can pull all the dates and display them on a page now I need to order the dates so they look like 12/5/00-12/8/00,12/10/00,12/12/00-12/14/00<BR><BR>So there could be dates missing in between and an end date which i pull from the form. I am pulling the dates from an array. I am going to use flags to dermine if I can add a date to combine them and another flag if not. I might be overcomplicating this but is this the best way to do it?<BR><BR>Matt

  2. #2
    Join Date
    Dec 1969

    Default RE: order dates

    I assume you are getting these dates from successive records in a RecordSet???<BR><BR>Hmmm...Just a bit of simple logic, then, I guess.<BR><BR>&#060;%<BR>Set RS = ...<BR>startDate = DateValue( RS("dateField") )<BR>priorDate = startDate<BR>RS.MoveNext<BR>Do While True<BR>&nbsp; &nbsp; If RS.EOF Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; nextDate = DateSerial( 5000, 1, 1 ) &#039 jan 1, 5000 -- dummy date!<BR>&nbsp; &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039 get real date from RS<BR>&nbsp; &nbsp; &nbsp; &nbsp; nextDate = DateValue( RS("dateField") )<BR>&nbsp; &nbsp; End If<BR>&nbsp; &nbsp; If DateDiff("d",priorDate,nextDate) = 1 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039 succeeding dates...keep track of first and last<BR>&nbsp; &nbsp; &nbsp; &nbsp; priorDate = nextDate<BR>&nbsp; &nbsp; Else <BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039 oops...a gap in dates...write out last date(s):<BR>&nbsp; &nbsp; &nbsp; &nbsp; If startDate = priorDate Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039 only one day:<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write startDate & ","<BR>&nbsp; &nbsp; &nbsp; &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039 a range of 2 or more successive dates:<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write startDate & "-" & priorDate & ","<BR>&nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039 and reset to new startdate:<BR>&nbsp; &nbsp; &nbsp; &nbsp; startDate = nextDate<BR>&nbsp; &nbsp; &nbsp; &nbsp; priorDate = startDate<BR>&nbsp; &nbsp; End If<BR>&nbsp; &nbsp; If RS.EOF Then Exit Do &#039 the dummy date forced final cleanup<BR>&nbsp; &nbsp; RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>Untested, but I think it makes sense.<BR><BR>It *will* put even pairs of adjacent dates into the 12/20/2000-12/21/2000 form. If that annoys you, it would be easy to fix.<BR><BR><BR><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