Datetime 水晶报表日期函数

Datetime 水晶报表日期函数,datetime,crystal-reports,Datetime,Crystal Reports,我试图只选择其日期从当前日期到三个月后的月末的记录 当前,表中有两个日期与查询匹配: 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

我试图只选择其日期从当前日期到三个月后的月末的记录

当前,表中有两个日期与查询匹配:

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
DateVar current=Date(CurrentDateTime)//请假
DateVar ThreeMonthsAway=日期(年(当前日期时间),月(当前日期时间)+4,1)-1;//月+4,然后-1天到最后一天还有三个月
{tblTenant.LeaseEnds}>当前和{tblTenant.LeaseEnds}<三个月远
问题是,它不会返回任何结果。如果我去掉第二部分,我会得到两个结果,但我只希望日期在三个月内


我做错了什么?

也许是因为你在未来增加了4个月,而不是减去它们

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

您是否打印出三个月以外的值,以查看其计算结果?您确定Date()的3参数形式采用了年-月-日顺序的参数吗(这是合理的,但我也遇到过顺序为月-日-年的系统)



这里提出的一些观点已经通过修正问题得到了解决(或者注释已经变得无关紧要,因为自注释提出以来问题已经修正)。

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

因此您的代码必须读取(不幸的是,我这里没有CR来测试它):

DateVar current:=日期(CurrentDateTime)//请假
DateVar三个月距离:=日期(年(CurrentDateTime),月(CurrentDateTime)+4,1)-1;//月+4,然后-1天到最后一天还有三个月
{tblTenant.LeaseEnds}>当前和{tblTenant.LeaseEnds}<三个月远

如何打印三个月之外的数据?如何打印任何其他变量或值?如果有必要,将其作为输出的一部分(至少在调试时)。我不知道如何打印crystal reports中的其他变量。好的-这就是我们两个人的原因。我还没有充分使用Crystal Reports来了解如何提供更多帮助-抱歉。如果Crystal Reports有一个调试器,我就可以一步一步地通过它查看值。。。
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