代码之家  ›  专栏  ›  技术社区  ›  Malfist

Crystal Reports日期函数

  •  1
  • Malfist  · 技术社区  · 15 年前

    我只想选择日期从当前日期到三个月后的月末的记录。

    当前表中有两个与查询匹配的日期:
    朱蒂:5/17/09
    ASDF:8/9/09

    这是我的公式:

    DateVar current = Date(DurrentDateTime); //takes the time off
    DateVar ThreeMonthsAway = Date(year(CurrentDateTime), month(CurrentDateTime)+4, 1) - 1; // month+4, then -1 days to get last day three months away
    {tblTenant.LeaseEnds} > current AND {tblTenant.LeaseEnds} < ThreeMonthsAway
    

    问题是,它不会返回任何结果。如果我去掉第二部分,我会得到两个结果,但我只希望日期在三个月内。

    我做错什么了?

    2 回复  |  直到 15 年前
        1
  •  1
  •   MicSim    15 年前

    从您的代码示例中,我猜您正在使用Crystal语法编写公式,因此变量赋值必须使用“:=”而不是“=”。“=”用于比较Crystal语法中的值。参见 here 例如。(可能您将它与基本语法混合在一起。)

    所以您的代码必须是可读的(不幸的是,这里没有CR来测试它):

    DateVar current := Date(CurrentDateTime); //takes the time off
    DateVar ThreeMonthsAway := Date(year(CurrentDateTime), month(CurrentDateTime)+4, 1) - 1; // month+4, then -1 days to get last day three months away
    {tblTenant.LeaseEnds} > current AND {tblTenant.LeaseEnds} < ThreeMonthsAway
    
        2
  •  0
  •   Jonathan Leffler    15 年前

    也许是因为你增加了4个月,而不是减少了4个月?

    你的问题要求“三个月前的月底”,但样本日期(截至2009年5月14日)在未来,所以可能是我误解了你的问题,或者你的问题写错了。

    您是否打印出了三个月的值,以查看它的评估结果?您确定date()的3参数形式采用年-月-日顺序的参数(这是合理的,但我也遇到过订单为月-日-年的系统)?


    这里提出的一些观点是通过修正问题来解决的(或者由于问题是在提出评论之后被修正的,所以评论变得不相关)。