How to convert DateTime object to string in Crystal Reports

后端 未结 2 1472
温柔的废话
温柔的废话 2020-12-20 19:07

I have a simple line of Crystal Reports code below:

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

H

相关标签:
2条回答
  • 2020-12-20 19:09

    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.

    0 讨论(0)
  • 2020-12-20 19:22

    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
    
    0 讨论(0)
提交回复
热议问题