Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(urgent!) Cannot add/subtract from a date

Status
Not open for further replies.

JenM

MIS
Oct 10, 2002
1
0
0
US
I have a report where I need to add or subtract a variable number from a date, and then compare it to another date. For example, I may need to add 4 days to date 1 and 9 days to date 2, then 5 days to date 3. I then need to know if the result of this calculation is more or less than the current date. I have tried simply adding the number to the date and comparing it(serial.orderdate + allowedage >= currentdate)and I have been unable to do this, getting no results back when I try and run it. Please help!
 
CurrentDate + 4
gives you the system date plus four days.
Instead of 4, you can use any variable with an integer value
Instead of CurrentDate, you can use any field/variable/expression that Crystal interprets as a date or datetime value.
I suspect that your field serial.orderdate is not a datetime value, but perhaps the serial form of a date.
 
One thing I've found (with version 7 anyway) is that when adding or subtracting from a date or datetime field is that the number being added or subtracted is going to the lowest possible denomination. Thus the following results:

{table.datefield} + 1 Will add 1 day to the date field.
{table.datetimefield} + 1 Will add 1 second to the datetime field.

For the last example, if you are only concerned with the date from the DateTime field, you can pull out the date then add 1 to it, such as Date({table.datetimefield}) + 1. That will then be the same as adding 1 day to a date field.
 
I have a similar problem, but I need to add variable number of varaible intervals - ie : I might need to add 1 day to one date and 3 months to another date. Ideally the 'DateAdd' function in VB would do this, but I need to get the result at runtime in Crystal. Is there anyway this can be done ?
 
from v8 help

DateAdd (intervalType, nIntervals, startDateTime)
examples
DateAdd ("h", -400, #Sept 28, 1999#)
DateAdd ("q", 17, #Sept 28, 1999#)
DateAdd("d", -32, #Sept 28, 1999#)
 
If you are using Crystal version 6 or 7 you can get the DateAdd dll from the seagate website. Go to and search for UFLDateAdd.exe. The readme.txt will tell you how to install it. They will need to be installed on all the computers where the report will be run.

Also, correction to my earlier post:

Adding and subtracting from Date or DateTime fields will add or subtract in Days. Adding and Subtracting from Time fields will add or subtract in seconds.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top