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

Why doesn't this formula work as I expect? 1

Status
Not open for further replies.

AyJayEL

Technical User
Jan 30, 2001
425
GB
I'm trying to write a formula to show the number of days either between a start date and an end date or where the end date is blank, to use today's date. It will only show where there is an end date and shows blank where there is no end date. Can anyone tell me what I'm doing wrong? See below.

Local DateTimeVar d1 := {VIEW_EXCL_SCHEDULE.START_DATE};
Local DateTimeVar d2 := {VIEW_EXCL_SCHEDULE.END_DATE};
Local DateTimeVar d3 := currentdate;

If (isnull({VIEW_EXCL_SCHEDULE.END_DATE}))
then
(DateDiff ("d", d1, d3) - DateDiff ("ww", d1, d3, crSaturday) -DateDiff("ww", d1, d3, crSunday))
else
(DateDiff ("d", d1, d2) - DateDiff ("ww", d1, d2, crSaturday) -DateDiff("ww", d1, d2, crSunday))


Learn something new every day *:->*
AyJayEl
 
No need for variables at all, just try this:

Code:
If isnull({VIEW_EXCL_SCHEDULE.END_DATE})then  DateDiff ("d", {VIEW_EXCL_SCHEDULE.START_DATE}, CurrentDate) 
else

DateDiff ("d", {VIEW_EXCL_SCHEDULE.START_DATE},{VIEW_EXCL_SCHEDULE.END_DATE})

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
Great, got rid of the variables but I the formula is still not working properly. I see a calculation for when there is an end date but it shows null when there is no end date.

Learn something new every day *:->*
AyJayEl
 
Try going to file->report options and see if you have "convert nulls to default values" checked, and try unchecking it. Otherwise you could try a test like:

if isnull({table.date}) or
{table.date} = date(0,0,0) then...

dgillz' formula left out the check for Saturdays and Sundays, which you would have to build back in.

-LB
 
I had already tried the 'convert nulls to default' turning them on and off to no avail! And I had spotted the lack of Saturdays and Sundays thanks.

When I try your little formula using 1 after then it displays 1 when the end date is blank and 0 when it has a value.



Learn something new every day *:->*
AyJayEl
 
How weird, suddenly it's started working! Thanks for your help chaps. Much appreciated.

Learn something new every day *:->*
AyJayEl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top