我正在尝试仅选择其日期从当前日期到现在三个月后的月末的记录。
目前,表格中有两个与查询匹配的日期:
Judy: 5/17/09
asdf: 8/9/09
这是我的公式:
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
问题是,它没有返回任何结果。如果我取消它的第二部分,我得到两个结果,但我只想要三个月内的日期。
我做错了什么?
答案 0 :(得分:2)
从您的代码示例中我猜您使用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
答案 1 :(得分:0)
也许是因为你增加了4个月 - 这是未来 - 而不是减去它们?
你问的问题是“三个月前的月末”,但是样本日期是(截至2009-05-14)未来,所以可能是我误解了你的问题,或者你的问题是误写入。
您是否打印出ThreeMonthsAway的值以查看其评估结果?你确定Date()的3参数形式采用年 - 月 - 日顺序中的参数(这是合理的,但我也遇到了订单是月 - 日 - 年的系统)?
这里提出的一些观点已经通过修复问题得到了解决(或者评论已经变得无关紧要,因为自提出意见以来问题已得到解决)。