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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to convert date fields.

Status
Not open for further replies.

Towim

Technical User
Dec 20, 2001
6
US
I need to create a formula using Crystal Reports 7.0, that will take a date field and increase that by a 2 fields. One that hold an integer that indicates how many months to add and one that holds an integer that indicates how many days to add.

HELP! Thanks in advance.

Example:

01/01/2001 + 3months + 10 days = 04/04/2001
 
If you have acces to the DateAdd function, you can use the following formula:

datevar end;datevar inter;
inter:=date(dateadd("m",{@MONTH ADD},{Original Date Field})) ;
end:=date(dateadd("d",{@DAY ADD},inter))

The UFL for the DateAdd function can be downloaded from:
Mike
 
I think DateAdd arrived with CR8. With CR7 you will need a formula with variables as follows:
numbervar y:=year({table.datefield});
numbervar m:=month({table.datefield})+ {table.monthadd};
numbervar d:=day({table.datefield}) + {table.dayadd};
numbervar dmax; //max days in a month

if m >12 then (y:=y+1; m:=m -12);// year overflow
dmax:= [31,28,31,30,31,30,31,31,30,31,30,31] [m] ;
if d > dmax then
(d:= d -dmax; m:=m+ 1);
if m >12 then (y:=y+1; m:=m -12);// check again
Date(y,m,d)

You might need to repeat some of these lines if you have more than 31 days or more than 12 months added into the calc

Editor and Publisher of Crystal Clear
 
Dateadd did arrive with Crystal 8 but it can be downloaded and used with lower versions as long as the computer running the report has access to the dateadd dll.

alley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top