Date calculation

Date calculation

am 03.01.2007 16:03:09 von Brett_A

I have the following code:

If ad_expiration_date > (date() + 90) then
ad_expiration_date = (date() + 90)
else
end if

What I want to happen is if the ad_expiration_date entered by the user
is beyond 90 days from today's date, the Expiration Date should be
today's date plus 90 days. If the entered date is less than 90 days
from today's date, leave it as entered.

The code isn't working correctly, all dates entered are getting
converted to today's date plus 90 days.

What's wrong?

Thanks.

Brett

Re: Date calculation

am 03.01.2007 16:50:14 von Daniel Crichton

Brett_A wrote on 3 Jan 2007 07:03:09 -0800:

> I have the following code:
>
> If ad_expiration_date > (date() + 90) then
> ad_expiration_date = (date() + 90)
> else
> end if
>
> What I want to happen is if the ad_expiration_date entered by the user
> is beyond 90 days from today's date, the Expiration Date should be
> today's date plus 90 days. If the entered date is less than 90 days
> from today's date, leave it as entered.
>
> The code isn't working correctly, all dates entered are getting
> converted to today's date plus 90 days.
>
> What's wrong?

Probably the date format - it may not be what you expect. For instance, if
ad_expiration_date is a string containing "7/12/2006", depending on the
date/time settings for the user account that your ASP code is running under
that date could be either 7th Dec 2006 or 12th Jul 2006. Also, if
ad_expiration_date is a string, it may be that the ASP code is converting
the (date() + 90) to a string prior to comparison - I can't remember the
data type coercion rules, so it's just a stab in the dark. To debug this,
add this bit of code just before the above code:

Response.Write ad_expiration_date & "
"
Response.Write CDate(ad_expiration_date) & "
"
Response.Write Date() + 90 & "
"

Hopefully from these 3 values you'll be able to spot why it's not working as
you expect it to.

Dan

Re: Date calculation

am 03.01.2007 17:18:36 von Brett_A

Dan,

Thanks for the quick response. Testing showed that the date was
getting processed as a string (I think - I'm no expert on ASP). Here
is the corrected and working code.

max_date = date() + 90

If CDate(ad_expiration_date) > max_date then
ad_expiration_date = max_date
else
end if

Thanks again.

Brett



Daniel Crichton wrote:
> Brett_A wrote on 3 Jan 2007 07:03:09 -0800:
>
> > I have the following code:
> >
> > If ad_expiration_date > (date() + 90) then
> > ad_expiration_date = (date() + 90)
> > else
> > end if
> >
> > What I want to happen is if the ad_expiration_date entered by the user
> > is beyond 90 days from today's date, the Expiration Date should be
> > today's date plus 90 days. If the entered date is less than 90 days
> > from today's date, leave it as entered.
> >
> > The code isn't working correctly, all dates entered are getting
> > converted to today's date plus 90 days.
> >
> > What's wrong?
>
> Probably the date format - it may not be what you expect. For instance, if
> ad_expiration_date is a string containing "7/12/2006", depending on the
> date/time settings for the user account that your ASP code is running under
> that date could be either 7th Dec 2006 or 12th Jul 2006. Also, if
> ad_expiration_date is a string, it may be that the ASP code is converting
> the (date() + 90) to a string prior to comparison - I can't remember the
> data type coercion rules, so it's just a stab in the dark. To debug this,
> add this bit of code just before the above code:
>
> Response.Write ad_expiration_date & "
"
> Response.Write CDate(ad_expiration_date) & "
"
> Response.Write Date() + 90 & "
"
>
> Hopefully from these 3 values you'll be able to spot why it's not working as
> you expect it to.
>
> Dan

Re: Date calculation

am 03.01.2007 17:34:34 von Daniel Crichton

Brett_A wrote on 3 Jan 2007 08:18:36 -0800:

> Dan,
>
> Thanks for the quick response. Testing showed that the date was
> getting processed as a string (I think - I'm no expert on ASP). Here
> is the corrected and working code.
>
> max_date = date() + 90
>
> If CDate(ad_expiration_date) > max_date then
> ad_expiration_date = max_date
> else
> end if
>
> Thanks again.

Glad it's sorted out. You know, you don't need that "else" as there's no
code between it and and the "end if", so it's competely unnecessary.

Dan

Re: Date calculation

am 03.01.2007 17:36:46 von reb01501

You need to go further with your debugging. Show us the results of:

Response.Write "ad_expiration_date contains '" & _
ad_expiration_date & "'
"

max_date = date() + 90
Response.Write "max_date contains '" & max_date & "'
"
Response.Write "CDate(ad_expiration_date) contains '" & _
CDate(ad_expiration_date) & "'
"


If CDate(ad_expiration_date) > max_date then
ad_expiration_date = max_date
else
end if

Brett_A wrote:
> Dan,
>
> Thanks for the quick response. Testing showed that the date was
> getting processed as a string (I think - I'm no expert on ASP). Here
> is the corrected and working code.
>
> max_date = date() + 90
>
> If CDate(ad_expiration_date) > max_date then
> ad_expiration_date = max_date
> else
> end if
>
> Thanks again.
>
> Brett
>
>
>
> Daniel Crichton wrote:
>> Brett_A wrote on 3 Jan 2007 07:03:09 -0800:
>>
>>> I have the following code:
>>>
>>> If ad_expiration_date > (date() + 90) then
>>> ad_expiration_date = (date() + 90)
>>> else
>>> end if
>>>
>>> What I want to happen is if the ad_expiration_date entered by the
>>> user is beyond 90 days from today's date, the Expiration Date
>>> should be today's date plus 90 days. If the entered date is less
>>> than 90 days from today's date, leave it as entered.
>>>
>>> The code isn't working correctly, all dates entered are getting
>>> converted to today's date plus 90 days.
>>>
>>> What's wrong?
>>
>> Probably the date format - it may not be what you expect. For
>> instance, if ad_expiration_date is a string containing "7/12/2006",
>> depending on the date/time settings for the user account that your
>> ASP code is running under that date could be either 7th Dec 2006 or
>> 12th Jul 2006. Also, if ad_expiration_date is a string, it may be
>> that the ASP code is converting the (date() + 90) to a string prior
>> to comparison - I can't remember the data type coercion rules, so
>> it's just a stab in the dark. To debug this, add this bit of code
>> just before the above code:
>>
>> Response.Write ad_expiration_date & "
"
>> Response.Write CDate(ad_expiration_date) & "
"
>> Response.Write Date() + 90 & "
"
>>
>> Hopefully from these 3 values you'll be able to spot why it's not
>> working as you expect it to.
>>
>> Dan

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: Date calculation

am 03.01.2007 17:59:12 von reb01501

Bob Barrows [MVP] wrote:
> You need to go further with your debugging. Show us the results of:
>
> Response.Write "ad_expiration_date contains '" & _
> ad_expiration_date & "'
"
>
Oops - disregard this
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: Date calculation

am 04.01.2007 02:57:11 von firas489

Hi there,

Try DateValue instead of CDate,
I think is the best, because it worked better with me in the past.


Best Regards
Firas S Assaad


Bob Barrows [MVP] wrote:
> Bob Barrows [MVP] wrote:
> > You need to go further with your debugging. Show us the results of:
> >
> > Response.Write "ad_expiration_date contains '" & _
> > ad_expiration_date & "'
"
> >
> Oops - disregard this
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.

Re: Date calculation

am 04.01.2007 03:23:31 von reb01501

Please explain its advantage and how it would be used in this case.

Firas S Assaad wrote:
> Hi there,
>
> Try DateValue instead of CDate,
> I think is the best, because it worked better with me in the past.
>
>
> Best Regards
> Firas S Assaad
>
>
> Bob Barrows [MVP] wrote:
>> Bob Barrows [MVP] wrote:
>>> You need to go further with your debugging. Show us the results of:
>>>
>>> Response.Write "ad_expiration_date contains '" & _
>>> ad_expiration_date & "'
"
>>>
>> Oops - disregard this
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"