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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect 1

Status
Not open for further replies.

lamchop

IS-IT--Management
Nov 4, 2002
6
CA
I need to do a redirect that works in the following way:
From Monday to Friday between 12:00am and 1:30am, and Saturday at 6pm to Sunday noon, I want my hyperlink to go to one page. But during all other hours, I want it to go to another page.

This is a pared down version of the html page that calls the .asp:

<html>
<head>
</head>
<body stylesrc=&quot;welcome.htm&quot;>
<td width=&quot;425&quot;><a href=&quot;redirect.asp&quot; target=&quot;_top&quot;>Click This Link</font></a></td>
</body>
</html>

This is the entire code in the redirect.asp page I am calling.
<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<% Option Explicit %>
<%
dim dteDateTime
dteDateTime = now
if (Weekday(dteDatetime) <> &quot;Sunday&quot;) OR (Weekday(dteDateTime) <>
&quot;Saturday&quot;)) then
if (time >= &quot;00:00&quot; and time <= &quot;01:30&quot;) then
response.redirect &quot; elseif (Weekday(dteDatetime) = &quot;Saturday&quot; and time >= &quot;6:00&quot;) OR
(Weekday(dteDateTime) = &quot;Sunday&quot; and time <= &quot;12:00&quot;) then
response.redirect &quot; else
response.redirect &quot; end if
end if
%>

The hosting server supports asp but I'm not quite sure why it's not working. Could someone help me figure out what's wrong? I don't really know much about ASP so it would be nice if someone can take a look at my code and see if something is missing.

Thanks!
 
For one thing weekday return the numeric version of the weekday from 1-7 (sunday to saturday).
I don't see your time variable declared anywhere, but you probably won't be able to get a good result with your current setup because it is going to try and do a string comparison. How about:
If hour(dteDateTime) = 0 Or (hour(dteDateTime = 1 AND minute(dteDateTime) < 30)) Then
'your less than 1:30am, greater than midnight code here

Another problem is that your elseif will never be reached because you are still in the if statement that said if not saturday or sunday, so you may want to restructure it like so:
For the heck of it, I decided to give the whole thing a shot, this isn't the prettiest way to do it, or the fastest, but:
Code:
If (WeekDay(now) = 1 And hour(Now) > 18) Or (WeekDay(now) = 7 and hour(now) < 12) or (weekday(now) > 1 and weekday(now) < 7 and (hour(now) = 0 or (hour(now)= 1 and minute(now) < 30))) Then
	Response.Write &quot;first page&quot;
Else
	Response.Write &quot;second page&quot;
End If

Problems with the above statement: The multiple calls to the time function will slow it down, plus the nature of ASP is to evaluate an entire statement before acting on it, so even if the first portion is correct it will still evaluate the entire expression. My advice would be to continue using your dteDateTime variable and split the above statement up into if, elseif statements with the most commonly occuring one first and the least common occuring one last.
On ething you might want t consider is setting up your structure so that the daytime page is the one you search for and the nighttime page is the final else.
Code:
Select Case WeekDay(now)
	Case 1 'Sunday
		If hour(now) > 12 then
			Response.Write &quot;daytime page sunday after noon&quot;
		Else
			Response.Write &quot;night page sunday before noon&quot;
		End If
	Case 7 'Saturday
		If hour(now) < 18 Then
			Response.Write &quot;daytime page, saturday before 6pm&quot;
		Else
			Response.Write &quot;daytime page, saturday after 6pm&quot;
		End If
	Case Else 'monday through friday
		If Hour(now) > 1 Then
			Response.Write &quot;M-F between 2Am and 11:59 pm&quot;
		ElseIf hour(now) = 1 And minute(now) > 30 Then
			Response.Write &quot;M-F between 1:30am and 2am&quot;
		Else
			Response.Write &quot;M-F between Midnight and 1:30am&quot;
		End If
End Select
Again, use your variable instead of the now function, but this ought to supply pages faster to people durin g the day when there is a heavier load and process more efficiently even at night time than my ugly if statement above.

Hope that helps :)
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top