ASP/VB Time comparison doing my nut!

Soldato
Joined
31 May 2006
Posts
4,239
Location
127.0.0.1
Hi all

I am trying to do a timetable view from a database list of events. The view works fine but for some (VERY) strange reason when I have anything at 11:30:00 AM (either the beginning of an event or end) it doesn't do the comparison correctly.

Below is a screen shot of what I mean:

screenie.jpg


The string in grey is the event name, ignore what is in the brackets, the number is a StrComp function on the EndTime and Current Time Block, the next one is the StartTime of the event (10:30:00 AM), the next time is the EndTime (11:30:00 AM) and lastly the last time shown is the current time block.

The comparison is shown below to see whether the information is displayed or not:

Code:
if cdate(rs_studenttimetable("Start")) =< cdate(tt_time) AND cdate(rs_studenttimetable("End")) > cdate(tt_time) then
		response.write "<td class='srchres1' bgcolor='#cccccc'>" & rs_studenttimetable("Reference") & " (" & rs_studenttimetable("Period Reference") & ") " & StrComp(cdate(rs_studenttimetable("End")),tt_time) & " - " & cdate(rs_studenttimetable("Start")) & " - " & cdate(rs_studenttimetable("End")) & " - " & cdate(tt_time) & "</td>"
		FoundALesson = 1
		Exit Do
	else
		
	end if

Then if
Code:
FoundALesson
isn't 1 then a link is shown with 'Make Appointment'.

The problem is that when it comes to test whether the EndTime of the event is BEFORE the Current Time Block for events that End (OR Start for that matter) at 11:30:00 AM it reports that it ISN'T before the Current Time Block and ends up showing the data!! For every other event start and end time configuration this doesn't happen!! It is driving me nuts!

The StrComp binary test shows they are the same (showing 0 in the screen shot) so how on earth can the if one is less than the other return true?!?!?
 
Try using the datediff function to test dates, rather than the standard operators. Normal operators sometimes mess with the variables' format and they become strings, which leads to strange outcomes like this.
 
Try using the datediff function to test dates, rather than the standard operators. Normal operators sometimes mess with the variables' format and they become strings, which leads to strange outcomes like this.

I could kiss you! Lol

Code now:

Code:
if datediff("n",cdate(rs_studenttimetable("Start")),cdate(tt_time)) => 0 then
 if datediff("n",cdate(rs_studenttimetable("End")),cdate(tt_time)) < 0 then
		response.write "<td class='srchres1' bgcolor='#cccccc'>" & rs_studenttimetable("Reference") & " (" & rs_studenttimetable("Period Reference") & ") " & StrComp(cdate(rs_studenttimetable("End")),tt_time) & " - " & cdate(rs_studenttimetable("Start")) & " - " & cdate(rs_studenttimetable("End")) & " - " & cdate(tt_time) & "</td>"
		FoundALesson = 1
		Exit Do
	else
		
	end if
end if

Works a treat! Thanks a million!!
 
Back
Top Bottom