473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

Jan 3 '07 #1
7 3871
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 & "<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
Jan 3 '07 #2
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 & "<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
Jan 3 '07 #3
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
Jan 3 '07 #4
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:
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 & "<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.
Jan 3 '07 #5
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 & "'<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.
Jan 3 '07 #6
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 & "'<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.
Jan 4 '07 #7
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 & "'<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"
Jan 4 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Manny Chohan | last post by:
Hi Can anyone tell me how i can calculate yesterday date using asp? Thanks manny
1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
1
by: mene | last post by:
I have a field that contains date information, and sometimes time information as well. I would like to be able to take that date and do a calculation on it. Here are some examples of what is in...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
3
by: Lindie | last post by:
We need to track how often a book has been loaned. We enter the dates and need an automatic calculation how often in the preceeding 12 months it has been taken out. box 1: today's date box 2:...
2
by: smcgrath via AccessMonster.com | last post by:
I have a table listing accounts with a closed date - our Trial balance drops the account after 7 days but our database keeps the record forever - How do I calculate the end of month less 7 days so...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
1
by: c8tz | last post by:
This is a query I have created that picks up the top 3 dates for this data (for example) : Tree Pos2 Date 1 15 23/08/2005 1 20 12/02/2006 1 32 15/10/2006 ...
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
16
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.