Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp not picking date properly

Status
Not open for further replies.

tyutghf

Technical User
Apr 12, 2008
258
GB
I have a calendar script highlights the day if there is an event in the database for that date.

The problem is that in the calendar script the date isn`t being picked out but in a basic page I created it works ok.

Here is the basic page, I have two events in my DB

Start_Date - 5/20/2009
End_Date - 5/20/2009
Event_Title - hello

and

Start_Date - 5/21/2009
End_Date - 5/21/2009
Event_Title - hello again

Here is my basic page

Code:
SQL = 	"SELECT DISTINCT Start_Date, End_Date, Event_Title FROM tEvents WHERE (Start_Date >='5/1/2009' AND Start_Date <= '5/31/2009') OR (End_Date >='5/1/2009' AND End_Date <= '5/31/2009') OR (Start_Date < '5/1/2009' AND End_Date > '5/31/2009' )ORDER BY Start_Date"
set rs = server.CreateObject("ADODB.RECORDSET")
rs.open SQL,objConn
	
if not rs.EOF then
do while not rs.EOF

response.write rs("Event_Title") & "<br />"

rs.MoveNext
loop

end if

and the output is correct:

hello
hello again

My problem comes when my calendar script looks for this date whilst looping through the calendar

Code:
<%
SQL = 	"SELECT DISTINCT Start_Date, End_Date, Event_Title FROM tEvents WHERE (Start_Date >='5/1/2009' AND Start_Date <= '5/31/2009') OR (End_Date >='5/1/2009' AND End_Date <= '5/31/2009') OR (Start_Date < '5/1/2009' AND End_Date > '5/31/2009' )ORDER BY Start_Date"
set rs = server.CreateObject("ADODB.RECORDSET")
rs.open SQL,objConn
%>
<table WIDTH="140" BORDER="0" CELLPADDING="1" CELLSPACING="0">
		<tr HEIGHT="18" BGCOLOR="Silver">
			<td WIDTH="20" HEIGHT="18" ALIGN="LEFT" VALIGN="MIDDLE"><a HREF="<% =sScript%>?month=<% =IntPrevMonth %>&amp;year=<% =IntPrevYear %>"><img SRC="images/prev.gif" WIDTH="10" HEIGHT="18" BORDER="0" ALT="Previous Month"></a></td>
			<td WIDTH="120" COLSPAN="5" ALIGN="CENTER" VALIGN="MIDDLE" CLASS="SOME"><% = strMonthName & " " & intThisYear %></td>
			<td WIDTH="20" HEIGHT="18" ALIGN="RIGHT" VALIGN="MIDDLE"><a HREF="<% =sScript %>?month=<% =IntNextMonth %>&amp;year=<% =IntNextYear %>"><img SRC="images/next.gif" WIDTH="10" HEIGHT="18" BORDER="0" ALT="Next Month"></a></td>
		</tr>
	  <tr>
			<td CLASS="SOME" WIDTH="20" HEIGHT="15" VALIGN="BOTTOM">S</td>
			<td CLASS="SOME" WIDTH="20" HEIGHT="15" VALIGN="BOTTOM">M</td>
			<td CLASS="SOME" WIDTH="20" HEIGHT="15" VALIGN="BOTTOM">T</td>
			<td CLASS="SOME" WIDTH="20" HEIGHT="15" VALIGN="BOTTOM">W</td>
			<td CLASS="SOME" WIDTH="20" HEIGHT="15" VALIGN="BOTTOM">T</td>
			<td CLASS="SOME" WIDTH="20" HEIGHT="15" VALIGN="BOTTOM">F</td>
			<td CLASS="SOME" WIDTH="20" HEIGHT="15" VALIGN="BOTTOM">S</td>
	  </tr>
	  <tr><td height="1" colspan="7" style='background-color: #cccccc'></td></tr>
			<%
			' Initialize the end of rows flag to false
			EndRows = False
			Response.Write vbCrLf
			
			' Loop until all the rows are exhausted
		 	Do While EndRows = False
				' Start a table row
				Response.Write "	<tr>" & vbCrLf
				' This is the loop for the days in the week
				For intLoopDay = cSUN To cSAT
					' If the first day is not sunday then print the last days of previous month in grayed font
					If intFirstWeekDay > cSUN Then
						Write_TD LastMonthDate, "NON"
						LastMonthDate = LastMonthDate + 1
						intFirstWeekDay = intFirstWeekDay - 1
					' The month starts on a sunday	
					Else
						' If the dates for the month are exhausted, start printing next month's dates
						' in grayed font
						If intPrintDay > intLastDay Then
							Write_TD NextMonthDate, "NON"
							NextMonthDate = NextMonthDate + 1
							EndRows = True 
						Else
							' If last day of the month, flag the end of the row
							If intPrintDay = intLastDay Then
								EndRows = True
							End If
							
							dToday = CDate(intThisMonth & "/" & intPrintDay & "/" & intThisYear)  
							dTodayFormat = CDate(intPrintDay & "/" & intThisMonth & "/" & intThisYear) 'added to display the date link in usa for the events page.
							
							If NOT Rs.EOF Then
								' Set events flag to false. This means the day has no event in it
								bEvents = False
							  Do While NOT Rs.EOF AND bEvents = False
									' If the date falls within the range of dates in the recordset, then 
									' the day has an event. Make the events flag True
							    If dToday >= Rs("Start_Date") AND dToday <= Rs("End_Date") Then
										' Print the date in a highlighted font
							      Write_TD "<a href=Event/?month=" & intThisMonth & "&year=" & intThisYear & "&date="& Server.URLEncode(dTodayFormat) & " class='event'>" & intPrintDay & "<br />" & rs("Event_Title") & "</a>", "HL"
										bEvents = True
									' If the Start date is greater than the date itself, there is no point
									' checking other records. Exit the loop	
							    ElseIf dToday < Rs("Start_Date") Then
										Exit Do
									' Move to the next record
									Else	
								    Rs.MoveNext
									End If
							  Loop
								' Checks for that day
								Rs.MoveFirst
							End If
							
							' If the event flag is not raise for that day, print it in a plain font
							If bEvents = False Then
								Write_TD "<a href=Event/?month=" & intThisMonth & "&year=" & intThisYear & "&date="& Server.URLEncode(dTodayFormat) & " class='noevent'>" & intPrintDay & "</a>", "SOME"
							End If
						End If 
						
						' Increment the date. Done once in the loop.
						intPrintDay = intPrintDay + 1
					End If
				
				' Move to the next day in the week
				Next
				Response.Write "	</tr>" & vbCrLf
				
			Loop 
			Rs.Close
	 	Set Rs = Nothing
		%>
	</table>

I should with this get the 20th in my output to have a class='event' and display the Event_Title but it is ignored and a class of NOEVENT is output.

Can you please please see where I have gone wrong?

thanks
 
Thanks to those that read this, I woke up in the middle of the night with the answer so it is all fixed now. I restructured the dates to change their format and all works fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top