PDA

View Full Version : Reocurring Event


Fellucca
04-03-2008, 06:29 PM
Please help! I have an events calendar and events are input as either one time events, daily repeating, weekly repeating, or monthly repeating and I'm trying to display them in date order one after the other for the next 10 days.

What I'm having trouble with is the reoccuring weekly events. I'm able to display each reoccurring event for each date throught the year it occurs, but I can't seem to limit the display to just from today through the next 10 days.

Also they're displaying by the originaly start date of the event and listing all the dates that event occurs instead of listing all the events in date order.

I highlighted in bold the piece of the code I'm having problems with.

<!--#include file="dsn.asp"-->
<!--#include file="func.asp"-->
<%
Set RS = Server.CreateObject("ADODB.Recordset")

' Get Calendar ID
CalendarID = request("CalendarID")
If Len(Trim(CalendarID)) = 0 Then
CalendarID = RSBODY("DefaultCalendar")
End If
If Len(Trim(CalendarID)) = 0 OR isNull(CalendarID) Then
SQL = "SELECT CalendarID FROM " & database_prefix & "Calendars ORDER BY CalendarID"
RS.Open SQL, Conn, 1, 3
If Not RS.EOF Then
CalendarID = RS("CalendarID")
Else
Response.redirect "admin.asp?Error=NoCalendar"
End If
RS.Close
End If

today = Date()
week = dateAdd("d",10,today)

convToday = year(date) &_
left("00",2-len(month(date))) & month(date) &_
left("00",2-len(day(date))) & day(date) & "000000"

convWeek = year(week) &_
left("00",2-len(month(week))) & month(week) &_
left("00",2-len(day(week))) & day(week) & "000000"

function starttimeFormat(num)
if len(num)=14 then
num=Mid(num,9,2) & Mid(num,11,2)
if num > "1259" then
num=(Left(num,2)) - 12 & ":" & Right(num,2) & " PM - "
elseif num >= "0001" AND num <= "1259" then
num=(Left(num,2)) & ":" & Right(num,2) & " AM - "
elseif num = "0000" then
num="All Day"
end if
else
num=num
end if
starttimeFormat=num
end function

function endtimeFormat(num)
if len(num)=14 then
num=Mid(num,9,2) & Mid(num,11,2)
if num > "1259" then
num=(Left(num,2)) - 12 & ":" & Right(num,2) & " PM"
elseif num >= "0001" AND num <= "1259" then
num=(Left(num,2)) & ":" & Right(num,2) & " AM"
elseif num = "0000" then
num=""
end if
else
num=num
end if
endtimeFormat=num
end function

function dateFormat(num)
if len(num)=14 AND (RS("StartDate"))>convToday then
num=Mid(num,5,2) & "/" & Mid(num,7,2) & "/" & Left(num,4)
else
num="Today"
end if
dateFormat=num
end function
%>

<%
SQL = "SELECT * FROM " & database_prefix & "Events WHERE CalendarID=" & CalendarID & " AND StartDate >= '" & convToday & "'" & " AND StartDate <= '" & convWeek & "' OR Recur>0 ORDER BY StartDate"
RS.Open SQL, Conn, 1, 3

Function ConvertDate(strDate)
strDay = Mid(strDate, 7, 2)
strMonth = Mid(strDate, 5, 2)
strYear = Left(strDate, 4)
strHour = Mid(strDate, 9, 2)
strMin = Mid(strDate, 11, 2)
strSec = Right(strDate, 2)

ConvertDate = strMonth & "/" & strDay & "/" & strYear
End Function


Do While Not RS.EOF

If RS("Recur") = 0 Then 'Event doesn't reoccur
noRecurEvent = ConvertDate(RS("StartDate")) & "" & startTimeFormat(RS("StartDate")) & "" & endTimeFormat(RS("EndDate")) & "" & RS("Name") & RS("Location") & "<br>"
'response.write noRecurEvent

End if

If RS("Recur") = 1 Then 'Event recurs daily everyday
intRecurringDays = DateDiff("d", ConvertDate(RS("StartDate")), ConvertDate(RS("RecurEndDate")))
For x = 0 To intRecurringDays

recurDaily = DateAdd("d", x, ConvertDate(RS("StartDate")))
'response.write recurDaily & ": " & RS("Name") & "<br>"

Next
End if


If RS("Recur") = 2 Then 'Event recurs weekly
x = 7

If RS("RecurEndDate") >= 0 Then
dEndDate = ConvertDate(RS("RecurEndDate"))
else
dEndDate = ConvertDate("20081231000000")
End if

recurWeekly = ConvertDate(RS("StartDate"))

while DateDiff("d", recurWeekly, dEndDate) >= 0
response.write recurWeekly & RS("Name") & "<BR>"
recurWeekly = DateAdd("d", x, recurWeekly)
wend
End If
RS.MoveNext
Loop
%>

Any suggestions would be greatly appreciated!

angst
04-03-2008, 07:01 PM
you could always try adding an end or expiry date for the event.

Fellucca
04-03-2008, 07:05 PM
you could always try adding an end or expiry date for the event.

Each event has an end date, some are 6 months from now, some never end.
So I've been able to display each event for the duration it occurs each week, but I'm having trouble confining that display to just the occurances over the next 10 days.

angst
04-03-2008, 07:12 PM
hmm, i'm confused. so if you only want it to display for 10 days, why wouldn't you just make that the expiry date?

sorry if I'm missing something here..

Fellucca
04-03-2008, 07:19 PM
hmm, i'm confused. so if you only want it to display for 10 days, why wouldn't you just make that the expiry date?

sorry if I'm missing something here..

Because as each day and week passes I want reocurring events to show up again next week and the week after etc. For example: If an event occurs every tuesday starting April 1st and ending in October then I want my list of events to show that event each tuesday. So on today's list, I want the April 8th occurance to be listed and then on Monday the 8th and the 15th occurance should display and so on and so on until the event ends in October.

Is that clearer?