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!
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!