Link to home
Start Free TrialLog in
Avatar of NewFocusConsult
NewFocusConsult

asked on

Creating a New date by adding Todays Date by a number

I have a Crystal Report that has a value of Today, the date the report is printed. I also calculate a value which is number of days in advance. I want to be able to get a new date by adding (today + Days in Advance). I have tried but get an error "The Number of Days is out of Range" Is there a way I can do this?
ASKER CERTIFIED SOLUTION
Avatar of Frank Helk
Frank Helk
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NewFocusConsult
NewFocusConsult

ASKER

My Formula I am using is as follows

CurrentDate + {@DaysInAdvance}

where {DaysInAdvance} = Rent_Due/Daily_Rent * -1

I still get "The number of days is out of range.
Have used DateAdd("d", -1, {TheDateFromDB}) and it works....thank you
The problem was probably that your Rent_Due / Daily_Rent calculation did not always produce an integer result.  For example, CurrentDate + (14 / 3) will give you that error, but CurrentDate + (14 / 2) works fine.  The DateAdd function seems to drop the decimal places from that argument, so it doesn't have that problem.

 FWIW, you could use CurrentDate + {@DaysInAdvance} if you made sure that the result from DaysInAdvance was an integer by rounding, or removing the decimal places.  You could use Truncate or Int to remove the decimal places, but Truncate and Int handle negative numbers differently, so which one you use would depend on how you wanted to handle those.  From the CR 10 Help:

Truncate (-10.2)
Returns -10.

Int (-10.2)
Returns -11.

 James