...

View Full Version : date calculations and display..



enrmpaga
04-26-2006, 11:51 AM
I'm creating a dvd hire webby for uni and i'm stuck on getting the return date to calculate aand was wondering if anyone could help me.. here is my code:

<%
Dim IDKEY, CUSTID, HireLength, DateAdd, days, Price, Dateofreturn

IDKEY=Request.form("IDKEY")

SQL_CUSTID = "SELECT * FROM cust WHERE CUSTID= 'Surname'"
SQL_CUSTID = CUSTID

HireLength= ChkString(Request.form("HireLength"))
days = CStr(HireLength)

response.write "Debug: HireLength = " & HireLength & "!"
response.flush

if Hirelength = "4" THEN
Price = "4.00"
Dateofreturn = (DateAdd("d",8,date()))
End if

if Hirelength = "7" THEN
Price = "6.00"
Dateofreturn = (DateAdd("d",11,date()))
End if

%>

<table border="0" cellpadding="4" cellspacing="2" align="center"><br>
<tr><td><b>Product ID:</b></td><td><%response.write(request.querystring("IDKEY"))%></td>
<td><b>Film:</b></td><td><%response.write(request.querystring("Film"))%></td>
<td><b>Length of Hire:</b></td><td><%response.write(request.querystring("HireLength") & "&nbsp;days")%></td></tr>
<tr><td><b>Price:</b></td><td><%response.write(Price)%></td>
<td><b>Hire Date:</b></td><td><%=Date()%></td>
<td><b>Return Date:</b></td><td><%response.write(Dateofreturn)%></td></tr>

</table>


<%


Set RS = Nothing

objConn.Close
Set objConn = Nothing
%>

enrmpaga
04-26-2006, 12:00 PM
the Price and Dateofreutrn should be displaying but they are not... the Hirelength value is cleary posted as 7, so with if statment Price should = 6 and Dateofreutrn should equal date +11 days.. but they aren't displaying, have made a simple syntax error in the IF statment?

degsy
04-26-2006, 12:19 PM
DateAdd is a functions. Don't Dim it.

Also you are mixing Request.Form and Request.QueryString in your code.

enrmpaga
04-26-2006, 01:09 PM
its definatly something to do with my if then statment:

HireLength=CStr(Request.querystring("HireLength"))

if HireLength = "4" THEN
Price = "4.00"
Dateofreturn = (DateAdd("d",8,date()))
End if

if HireLength = "7" THEN
Price = "6.00"
Dateofreturn = (DateAdd("d",11,date()))
Else
Price = "Invalid"
Dateofreturn = "Invalid"
end if
%>
<table border="0" cellpadding="4" cellspacing="2" align="center"><br>
<tr><td><b>Product ID:</b></td><td><%response.write(request.querystring("IDKEY"))%></td>
<td><b>Film:</b></td><td><%response.write(request.querystring("Film"))%></td>
<td><b>Length of Hire:</b></td><td><%response.write(request.querystring("HireLength") & "&nbsp;days")%></td></tr>
<tr><td><b>Price:</b></td><td><%response.write(Price)%></td>
<td><b>Hire Date:</b></td><td><%=Date()%></td>
<td><b>Return Date:</b></td><td><%response.write(Dateofreturn)%></td></tr>

</table>

Price/Date of return are currently displaying as invalid..

They shouldn't HireLength is passed through the url as equal to 4 or 7 so price and dateofhire should be equal to the conidtion i have set..

degsy
04-27-2006, 03:57 PM
Your code is fine. Fix the two points I mentioned.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum