如何在Crystal Reports中将DateTime对象转换为字符串

时间:2013-12-12 16:28:39

标签: datetime crystal-reports

我在下面有一行简单的Crystal Reports代码:

EffectiveDateTimeString = ToText({Command.EffectiveDate} , "dd-MM-yyyy hh:mm:ss" );

然而,当我尝试验证公式时,我收到一条错误,说“选择了”dd-MM-yyyy hh:mm:ss“这个函数的参数太多了”。 Command.EffectiveDate是DateTime对象。如何将其转换为字符串?

谢谢!

2 个答案:

答案 0 :(得分:4)

您需要使用赋值运算符:=,而不是等效=

EffectiveDateTimeString := ToText({Command.EffectiveDate} , "dd-MM-yyyy hh:mm:ss" );

* 编辑*

此代码段按预期工作:

ToText(CurrentDate + CurrentTime, "dd-MM-yyyy hh:mm:ss");

确保您的字段实际上返回的是日期/时间,而不是其中一个。

答案 1 :(得分:1)

试试这个:

EffectiveDateTimeString := CStr(DateTime({Command.EffectiveDate} , "dd/MM/yyyy hh:mm:ss" ));

如果{Command.EffectiveDate}的格式不正确,这将确保它确实是DateTime。

如果这不起作用,我只是在我的示例报告中创建了一个简单的公式,下面的代码在DateTime字段上运行得很好:

stringVar EffectiveDateTimeString;
EffectiveDateTimeString := CStr({Command.EffectiveDate}, "dd/MM/yyyy hh:mm:ss");
EffectiveDateTimeString
相关问题