Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert DateTime object to string in Crystal Reports

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!

like image 341
SpartaSixZero Avatar asked Dec 12 '13 16:12

SpartaSixZero


People also ask

How do I change the date format in Crystal Reports?

If you have a DateTime field in Crystal Reports, you will see Date and Time tab option on the Format Editor when you right-click on the field and select Format Field menu item. From the Date and Time tab, you may select the desired format and select OK.

How do I change the datatype of a field in Crystal Report?

To set field default formatting, select File, Options from the menu bar and click the Fields tab. Field formats are set based on the field type you select. There are five field types: String, Number, Currency, Date, and Boolean.


1 Answers

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.

like image 106
craig Avatar answered Oct 04 '22 18:10

craig