如何在基本语法模式下使用 Crystal Reports 中的 DateAdd 函数

发布于 2025-01-16 09:35:11 字数 477 浏览 2 评论 0原文

我在 Crystal Reports 中有一个用基本语法编写的公式,以便将其与 HTML 文本解释一起使用。在代码的一部分中,我想在今天的日期上添加六个月。我知道 DateAdd 函数可以执行此操作,但我不断收到错误消息,指出需要日期。我知道 DateAdd 函数在 Crystal 语法模式下可以正常工作,但我需要保持基本语法模式才能使公式中的其他代码正常工作。在 Crystal Reports 的基本语法模式下使用 DateAdd 的正确方法是什么?

我尝试使用与此类似的代码:

dim sdate as date 
sdate = DateAdd("m", 6, Today) 
formula = sdate

当我尝试保存它时,它返回一个错误并突出显示 DateAdd 函数和参数 ("DateAdd("m", 6, Today") 并说

“此处需要日期。”

I have a formula in Crystal Reports that is written in Basic Syntax in order for it to be used with the HTML text interpretation. In one part of the code, I would like to add six months to Today's date. I know the DateAdd function can do this but I keep getting an error stating that a date is required. I know that the DateAdd function works without any problems in Crystal Syntax Mode, but I need to remain in Basic Syntax mode in order for the other code in the formula to work. What is the proper way to use DateAdd in Basic Syntax mode in Crystal Reports?

I tried using code similar to this:

dim sdate as date 
sdate = DateAdd("m", 6, Today) 
formula = sdate

When I try to save it, it returns an error and highlights the DateAdd function and the arguments ("DateAdd("m", 6, Today") and says

"A date is required here."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2025-01-23 09:35:11

DateAdd 函数返回一个 DateTime,但 sdate 被声明为 Date

因此有两种可能性:

  1. 如果需要时间部分,请将 sdate 声明为 DateTime 并使用 CurrentDateTime 而不是 Today :

    将 sdate 变暗为日期时间
    sdate = DateAdd("m", 6, 当前日期时间)
    公式 = 日期
    

  2. If时间部分不是必需的,将DateAdd的结果转换为Date

    Dim sdate 作为日期
    sdate = CDate(DateAdd("m", 6, 今天))
    公式 = 日期
    

The DateAdd function returns a DateTime, but sdate is declared as Date.

So there are two possibilities:

  1. If the time part is required, declare sdate as DateTime and use CurrentDateTime instead of Today :

    Dim sdate As DateTime
    sdate = DateAdd("m", 6, CurrentDateTime)
    formula = sdate
    
  2. If the time part is not required, convert the result of DateAdd to Date :

    Dim sdate As Date
    sdate = CDate(DateAdd("m", 6, Today))
    formula = sdate
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文