简体   繁体   中英

Crystal Reports if then, variables and dates

I need to create a crystal formula to look for a specific number in a record, if that number exist then create a date/time variable. Look for a second record with a different specific number and create a second date/time var. Then calculate a date diff between the two var. Im new to crystal and am stumped any help would be appreciated. this is what I have and it obviously does not work. "EVNT_CD" 10 will always be a start date and "EVENT_CD" 11 will always be the end date. thanks dave

IF {WKWOEVENTS.WE_EVNT_CD} = 10
then local DateTimeVar d1 := {WKWOEVENTS.WE_EVNT_DT}+{WKWOEVENTS.WE_EVNT_TM}
IF {WKWOEVENTS.WE_EVNT_CD} = 11
then local DateTimeVar d2 := {WKWOEVENTS.WE_EVNT_DT}+{WKWOEVENTS.WE_EVNT_TM}
DateDiff ("h",d1,d2)

I would break this up into 3 separate formulas:

1)

IF {WKWOEVENTS.WE_EVNT_CD} = 10
then shared DateTimeVar d1 := {WKWOEVENTS.WE_EVNT_DT}+{WKWOEVENTS.WE_EVNT_TM}

2)

IF {WKWOEVENTS.WE_EVNT_CD} = 11
then shared DateTimeVar d2 := {WKWOEVENTS.WE_EVNT_DT}+{WKWOEVENTS.WE_EVNT_TM}

3)

shared DateTimevar d1;
shared DateTimeVar d2;
DateDiff ("h",d1,d2)

Breaking this up into 3 formulas brings the need to change the variables from local to shared. You will also need to make sure to put the formulas in the correct order. The 3rd formula needs to be positioned so it gets evaluated After formula 1 and 2. You might get an error if {WKWOEVENTS.WE_EVNT_DT} and {WKWOEVENTS.WE_EVNT_TM} are not the right data format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM