Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 3rd, 2007, 03:05 PM
Brett_A
Guest
 
Posts: n/a
Default Date calculation

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

  #2  
Old January 3rd, 2007, 03:55 PM
Daniel Crichton
Guest
 
Posts: n/a
Default Re: Date calculation

Brett_A wrote on 3 Jan 2007 07:03:09 -0800:
Quote:
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 & "<br>"
Response.Write CDate(ad_expiration_date) & "<br>"
Response.Write Date() + 90 & "<br>"

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

Dan


  #3  
Old January 3rd, 2007, 04:25 PM
Brett_A
Guest
 
Posts: n/a
Default Re: Date calculation

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:
Quote:
Brett_A wrote on 3 Jan 2007 07:03:09 -0800:
>
Quote:
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 & "<br>"
Response.Write CDate(ad_expiration_date) & "<br>"
Response.Write Date() + 90 & "<br>"
>
Hopefully from these 3 values you'll be able to spot why it's not working as
you expect it to.
>
Dan
  #4  
Old January 3rd, 2007, 04:45 PM
Daniel Crichton
Guest
 
Posts: n/a
Default Re: Date calculation

Brett_A wrote on 3 Jan 2007 08:18:36 -0800:
Quote:
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


  #5  
Old January 3rd, 2007, 04:45 PM
Bob Barrows [MVP]
Guest
 
Posts: n/a
Default Re: Date calculation

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

Response.Write "ad_expiration_date contains '" & _
ad_expiration_date & "'<br>"

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


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

Brett_A wrote:
Quote:
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:
Quote:
>Brett_A wrote on 3 Jan 2007 07:03:09 -0800:
>>
Quote:
>>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 & "<br>"
>Response.Write CDate(ad_expiration_date) & "<br>"
>Response.Write Date() + 90 & "<br>"
>>
>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.


  #6  
Old January 3rd, 2007, 05:05 PM
Bob Barrows [MVP]
Guest
 
Posts: n/a
Default Re: Date calculation

Bob Barrows [MVP] wrote:
Quote:
You need to go further with your debugging. Show us the results of:
>
Response.Write "ad_expiration_date contains '" & _
ad_expiration_date & "'<br>"
>
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.


  #7  
Old January 4th, 2007, 02:05 AM
Firas S Assaad
Guest
 
Posts: n/a
Default Re: Date calculation

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:
Quote:
Bob Barrows [MVP] wrote:
Quote:
You need to go further with your debugging. Show us the results of:

Response.Write "ad_expiration_date contains '" & _
ad_expiration_date & "'<br>"
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.
  #8  
Old January 4th, 2007, 02:35 AM
Bob Barrows [MVP]
Guest
 
Posts: n/a
Default Re: Date calculation

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

Firas S Assaad wrote:
Quote:
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:
Quote:
>Bob Barrows [MVP] wrote:
Quote:
>>You need to go further with your debugging. Show us the results of:
>>>
>>Response.Write "ad_expiration_date contains '" & _
>>ad_expiration_date & "'<br>"
>>>
>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"


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles