PDA

View Full Version : Date Between Help and Advice


james6380
02-19-2008, 03:57 PM
Help having problems amending code to affect my hotel booking system I have 4 Prices for LOW, HIGH, Illuminations, BANK HOLIDAY

<%response.write(request.form("Day"))%>
&nbsp;
<%response.write(request.form("Month"))%>
&nbsp;
<%response.write(request.form("Year"))%>

<%

' -- GRAB CODE FEATURE --

strDay = Request.Form("Date")
strMonth = Request.Form("Month")
strYear = Request.Form("Year")
AdultNo = Request.Form("AdultNo")
ChildNo = Request.Form("ChildNo")
NoNights = Request.Form("NoNights")


' -- Grab Price Based on Month --

Select Case strDay strMonth strYear

' -- Low Season from Jan - April --
Case "1 January 2008 > 30 April 2008"
AdultPrice = 25.00
ChildPrice = 11.00

' -- High Season from May - Aug --
Case "1 May 2008 > 31 August 2008"
AdultPrice = 31.50
ChildPrice = 12.50

' -- Illuminations Season from September - November --
Case "1 September 2008 > 30 November 2008"
AdultPrice = 39.88
ChildPrice = 19.99

' -- Bank Holidays --
' ----------------------------------------
' -- (21 March 2008 - 24 March 2008) --
' -- (3 May 2008 - 5 May 2008) --
' -- (23 May 2008 - 26 May 2008) --
' -- (22 August 2008 - 25 August 2008) --
' ----------------------------------------

Case "21 March 2008 > 24 March 2008"
AdultPrice = 49.88
ChildPrice = 29.99

Case "3 May 2008 > 5 May 2008"
AdultPrice = 49.88
ChildPrice = 29.99

Case "23 May 2008 > 26 May 2008"
AdultPrice = 49.88
ChildPrice = 29.99

Case "23 May 2008 > 26 May 2008"
AdultPrice = 49.88
ChildPrice = 29.99

Case "22 August 2008 > 25 August 2008"
AdultPrice = 49.88
ChildPrice = 29.99

End Select

' -- Calculate Prices --

intAdultTotal = CDbl(AdultPrice) * (AdultNo)
intChildTotal = CDbl(ChildPrice) * (ChildNo)
intTotal = CDbl((intAdultTotal + intChildTotal) * NoNights)

' -- Illuminations Season from September - November --
Case "1 September 2008 > 30 November 2008"
AdultPrice = 39.88
ChildPrice = 19.99

Am I doing the wrong code as I keep getting

-----------------------------------------------

Microsoft VBScript compilation error '800a03ea'

Syntax error

/booking/step2.asp, line 54

Case "1 January 2008 > 30 April 2008"
^
-----------------------------------------------

angst
02-19-2008, 04:50 PM
ok, first of all,
I'm not sure that using this date format will work: Case "1 January 2008 > 30 April 2008"
also, you should cast the string as a date, like:

maybe try:

Case cDate("01/01/2008") > cDate("30/04/2008")

james6380
02-19-2008, 04:55 PM
Okay going off your advice

When I select 1st January 2008 it comes out into the next page as below

Date comes out like this
DAY = 1
Month = 1
Year = 2008

strDay = Request.Form("Day")
strMonth = Request.Form("Month")
strYear = Request.Form("Year")

' -- Grab Price Based on Month --

Select Case "strDay", "strMonth", "strYear"

' -- Low Season from Jan - April --
Case cDate("01/01/2008") > cDate("30/04/2008")
AdultPrice = 25.00
ChildPrice = 11.00

' -- High Season from May - Aug --
Case cDate("01/05/2008") > cDate("30/06/2008")
AdultPrice = 31.50
ChildPrice = 12.50

james6380
02-19-2008, 06:15 PM
' -- GRAB CODE FEATURE --

strDay = Request.Form("Day")
strMonth = Request.Form("Month")
strYear = Request.Form("Year")
AdultNo = Request.Form("AdultNo")
ChildNo = Request.Form("ChildNo")
NoNights = Request.Form("NoNights")


' -- Grab Price Based on Month --

Select Case strDay strMonth strYear

' -- Low Season from Jan - April --
Case cDate("01/01/2008") > cDate("30/04/2008")
AdultPrice = 25.00
ChildPrice = 11.00

' -- High Season from May - Aug --
Case cDate("01/05/2008") > cDate("30/06/2008")
AdultPrice = 31.50
ChildPrice = 12.50

End Select

' -- Calculate Prices --

intAdultTotal = CDbl(AdultPrice) * (AdultNo)
intChildTotal = CDbl(ChildPrice) * (ChildNo)
intTotal = CDbl((intAdultTotal + intChildTotal) * NoNights)

But when I run this i get

Microsoft VBScript compilation error '800a03ea'

Syntax error

/booking/step2.asp, line 54

Case cDate("01/01/2008") > cDate("30/04/2008")


HELP PLEASE

Whatever Jr.
02-20-2008, 11:03 AM
Try converting all the dates to Julian dates. That should help.

HTH, Tom

Spudhead
02-20-2008, 01:01 PM
Firstly, I've never seen this before:
Select Case strDay strMonth strYear
if you can send three variables to a select case statement I'd be very surprised. I've not seen a reference that says you can. So convert your strDay strMonth strYear into a single Date variable.

Secondly, I can't see how this is going to evaluate as you're expecting it to:

cDate("01/01/2008") > cDate("30/04/2008")

With Select Case, you can compare a variable to a list of one or more conditions. As far as I can see, the condition above will evaluate to boolean false. So you're comparing three string values to false: this is not good.

Personally, I wouldn't use Select Case for this. In VB you can use the To operator to define a range of values as a case, but not in VBScript. It would probably be more elegant to use a standard set of If..Else, but here's one way of doing it with Select:

dim dtLowOpen, dtLowClose, dtHighOpen, dtHighClose
dtLowOpen = cDate("1/1/2008")
dtLowClose = cDate("30/4/2008")
dtHighOpen = cDate("1/5/2008")
dtHighClose = cDate("31/8/2008")

dim sDay, sMonth, sYear, dtDate
sDay = "20"
sMonth = "6"
sYear = "2008"
dtDate = cDate(sDay & "/" & sMonth & "/" & sYear)

select case true
case dtDate > dtLowOpen and dtDate < dtLowClose
response.write("low")
case dtDate > dtHighOpen and dtDate < dtHighClose
response.write("high")
end select