Crystal Reports选择标准:选定的日期代码清理

时间:2011-10-25 16:50:49

标签: crystal-reports crystal-reports-8.5

我有一份定期报告,每月运行两次,以检查具体日期。 我正在寻找不会在接下来的15日或下个月的最后一天发生的任何事情。

如果它有所作为,我正在使用Crystal Reports 8.5。

我找到了一种自动化这个过程的方法,但它非常笨重。我想知道以下代码是否有更优雅的解决方案:

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)))

1 个答案:

答案 0 :(得分:0)

您可以使用此公式获取该月的最后一天。用简单的英语,它将返回“下个月第一天的前一天”:

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

“下个月15日”仅略有不同:

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

将这两者结合起来,最终的记录选择如下:

not({gb_comb_stmt.nxt_stmt_dt} = {@formula1})
and not({gb_comb_stmt.nxt_stmt_dt} = {@formula2})