Announcement

Collapse
No announcement yet.

ASP/VB Time comparison doing my nut!

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • ASP/VB Time comparison doing my nut!

    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:



    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?!?!?
    Server 2000 MCP
    Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

  • #2
    Re: ASP/VB Time comparison doing my nut!

    I was given the idea for a solution on another forum and I thought I'd share it with you guys should anyone else have a similar issue:

    Using datediff for the comparison rather than the standard operators.

    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.
    Server 2000 MCP
    Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    Comment

    Working...
    X