Question

I have a recurring report that is run twice a month to check for specific dates. I'm looking for anything that doesn't fall on the next 15th or the next last day of the month.

I'm using Crystal Reports 8.5 if it makes a difference.

I found a way to automate this process, but it's very bulky. I'm wondering if there is a more elegant solution to the following code:

if DatePart ("d", CurrentDate) < 15 then
    not ((DatePart ("d", {gb_comb_stmt.nxt_stmt_dt}) = 15  and
        DatePart ("m", {gb_comb_stmt.nxt_stmt_dt}) = DatePart ("m", CurrentDate) and
        DatePart ("yyyy", {gb_comb_stmt.nxt_stmt_dt}) = DatePart ("yyyy", CurrentDate))

        or (DatePart ("d", {gb_comb_stmt.nxt_stmt_dt}) = DatePart("d", DateAdd("d", -1 , DateAdd("m", 1 , Date(year(currentDate), month(currentDate), 1))))  and
        DatePart ("m", {gb_comb_stmt.nxt_stmt_dt}) = DatePart ("m", CurrentDate) and
        DatePart ("yyyy", {gb_comb_stmt.nxt_stmt_dt}) = DatePart ("yyyy", CurrentDate)))
else
    not ((DatePart ("d", {gb_comb_stmt.nxt_stmt_dt}) = 15  and
        DatePart ("m", {gb_comb_stmt.nxt_stmt_dt}) = (DatePart ("m", CurrentDate) + 1) and
        DatePart ("yyyy", {gb_comb_stmt.nxt_stmt_dt}) = DatePart ("yyyy", CurrentDate))

        or (DatePart ("d", {gb_comb_stmt.nxt_stmt_dt}) = DatePart("d", DateAdd("d", -1 , DateAdd("m", 1 , Date(year(currentDate), month(currentDate), 1))))  and
        DatePart ("m", {gb_comb_stmt.nxt_stmt_dt}) = DatePart ("m", CurrentDate) and
        DatePart ("yyyy", {gb_comb_stmt.nxt_stmt_dt}) = DatePart ("yyyy", CurrentDate)))
Was it helpful?

Solution

You can get the last day of the month with this formula. In plain English, it is returning "the day before the first day of next month":

dateserial(year(currentdate),month(currentdate)+1,1-1)

The "next 15th of the month" is only slightly different:

if datepart("d",currentdate) < 16
     then dateserial(year(currentdate),month(currentdate),15)
else
     dateserial(year(currentdate),month(currentdate)+1,15)

Combining these two, the final record selection will look like this:

not({gb_comb_stmt.nxt_stmt_dt} = {@formula1})
and not({gb_comb_stmt.nxt_stmt_dt} = {@formula2})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top