Forums

ASP

This topic is locked

date comparison problem

Posted 23 Jan 2008 06:53:44
1
has voted
23 Jan 2008 06:53:44 Javier Castro posted:
Hi Guys,

I'm stuck on a problem.
I have a registration page where from a drop down menu the user can select the type of the desire membership. To keep it short:
If the user registers on the first quarter of the year, then the charge would be full $ 100, if the user registers the second quarter of the year, then the price is $75 and so on. The price is prorated.
However I can't seem to figure this one out.

I tried passing an arbitrary date to test first and created a form with a field to pass a date. oN a response page, the following code

<pre id=code><font face=courier size=2 id=code> &lt;% Dim myMonth,myDate, myPrice

myMonth=Request.Form("myMonth"

myDate = Now()

if myMonth = DateAdd("q", 1, myDate) then
myPrice = 100
ElseIf myMonth = DateAdd("q", 2, myDate) then
myPrice = 75
Else
end if

%&gt;</font id=code></pre id=code>

Any ideas???? please??? using Classic ASP

Replies

Replied 23 Jan 2008 18:12:06
23 Jan 2008 18:12:06 Vince Baker replied:
try setting things a bit different,

Dim another variable myMonthAdded

then

myMonthAdded = DateAdd("q",1, myDate)

and relplace

if myMonth = DateAdd("q", 1, myDate) then WITH if myMonth = myMonthAdded


I would also look at the result of the dateAdd as dates can do funny things if you dont format them before comparing them.

let me konw

Regards

Vince Baker
<strong>DMX Zone Manager</strong>

[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Replied 23 Jan 2008 18:20:32
23 Jan 2008 18:20:32 Javier Castro replied:
Hi Vince,

Thanks for your input. I actually JUST found a solution to my problem by using DatePart instead of DateAdd. Now I'm not a programmer and I don't know if my coding is elegant enough but here we go:

<pre id=code><font face=courier size=2 id=code>&lt;% Dim sDate, dpDate, myPrice
sDate=Request.Form("myDate" 'myDate is the input from a form on another page that It's grabbed on sDate -- just for testing
'DatePart("q",sDate)
dpDate = DatePart("q",sDate)
If dpDate = 1 Then
myPrice = 100
ElseIf dpDate = 2 Then
myPrice = 75
ElseIf dpDate = 3 Then
myPrice = 50
ElseIf dpDate = 4 Then
myPrice = 25
End If
%&gt; </font id=code></pre id=code>

would you have done it differently? let me know.

Cheers,

Javier
Replied 24 Jan 2008 13:23:07
24 Jan 2008 13:23:07 Vince Baker replied:
Simularly to you, but I would use select case rather than many if elseifs,

Select case dpDate

Case 1
myPrice = 100

case 2
myPrice = 75

case 3
myPrice = 50

case 4
myPrice = 25

end select

But not that this make smuch difference.... just how I would do it

Regards

Vince Baker
<strong>DMX Zone Manager</strong>

[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]

Reply to this topic