Crystal Report Date公式使其成为月末

时间:2012-08-06 23:30:21

标签: date crystal-reports formula

我是CR的新手,需要一个公式,可以让我在一个日期字段中结束月份a。 如果日期是628/2012或2012年7月12日,我需要公式为月末,无论该字段显示的月份中的哪一天。当然,我们知道不是每个月都会在30日或31日结束,而有时会在29日或30日结束。那么我可以使用什么公式来做到这一点

示例字段名称{table.end_date}

非常感谢任何帮助。

提前致谢。

1 个答案:

答案 0 :(得分:4)

创建公式字段以计算月末:

//{@EndOfMonth}
// find the first day of the month, add a month to it, then subtract a day
DateAdd("m", 1, DateTime( Year({table.dateField}), Month({table.dateField}), 1, 0,0,0 )) - 1

创建第二个公式,生成文本表示:

//{@TextRepresentation}
If Isnull({table.end_date}) Then
  Space(8)
Else
  ToText({@EndOfMonth}, "YYYYMMDD")