How to convert DateTime object to string in Crysta

2019-02-22 10:47发布

I have a simple line of Crystal Reports code below:

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

However, when I try to validate the formula, I get a error saying "Too many arguments have been given to this function" with "dd-MM-yyyy hh:mm:ss" selected. Command.EffectiveDate is the DateTime object. How can I convert this to a string?

Thanks!

2条回答
【Aperson】
2楼-- · 2019-02-22 10:57

Try this:

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

If {Command.EffectiveDate} is not in the right format, this will ensure that it is indeed DateTime.

If that doesn't work, I just created a simple formula in a sample report of mine, and the below code worked just fine on a DateTime field:

stringVar EffectiveDateTimeString;
EffectiveDateTimeString := CStr({Command.EffectiveDate}, "dd/MM/yyyy hh:mm:ss");
EffectiveDateTimeString
查看更多
够拽才男人
3楼-- · 2019-02-22 11:02

You need to use the assignment operator :=, not the equivalency one =:

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

*edit *

This snippet works as expected:

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

Ensure that your field is actually returning a date/time, rather than one or the other.

查看更多
登录 后发表回答