【问题标题】:Is there a quick and easy way to print the end of the month date on a crystal report?有没有一种快速简便的方法可以在水晶报表上打印月末日期?
【发布时间】:2014-08-20 03:53:00
【问题描述】:

我正在 Crystal Reports 中构建一个非常简单的报表,我们需要它打印该月的最后一天,根据打印它的月份。

由于打印日期等“特殊字段”,我认为 Crystal 有某种方式可以做到这一点。还是我必须写一个 if-then-else?

【问题讨论】:

标签: crystal-reports


【解决方案1】:

另一种在报告中打印月末的方法是使用此公式

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

它会给你当月的最后一天,如果你需要一个月前只需在这部分代码中减去 1 month(currentdate)+1 并在一个月后加 1 等等等等

【讨论】:

  • 我遇到的唯一问题是它在 2 个月前打印,而不是 1 个月前打印。所以,我们在八月,它打印六月。
  • 七月:dateserial(year(currentdate),month(currentdate),1-1)
  • 不客气@AliciaUhacz。很高兴能帮到你。
【解决方案2】:

我使用了这里讨论的公式:Crystal Report Date formula to make it the end of the month,这对我有用,但做了一些改动。我将其更改为适合我的目的如下:

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

【讨论】:

    【解决方案3】:

    试试这个:

    CDate(DateAdd("d", -1, DateSerial(Year(CurrentDate), Month(CurrentDate) + 1, 1)))
    

    【讨论】:

    • 我创建了一个公式 (EndOfMonth),如下所示: //{@EndOfMonth} // 找到该月的第一天,给它加上一个月,然后减去一天 DateAdd("m ", 1, DateTime( Year(CurrentDate), Month(CurrentDate), 1, 0,0,0 )) - 1
    • @KristoferA 我已经测试了该解决方案,并且无论选择月份报告如何,它都能正常工作...您可以在此解决方案失败的地方添加您的 cmets 吗?
    • @Siva 你是对的:显然 VBA DateSerial 可以对无效日期进行翻转,并接受 13 的月份值......我曾预计它会失败。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多