Search code examples
crystal-reports

Crystal Reports add a database field to string date


I have a field {OperationHeader.ReceiptDate} in my report which saves the date of the document in a string (e. g. "07.04.2014") . I need to create a formula which adds to this field another database field {OperationDetails.GoodsPriceOut10} containing a number.


Solution

    1. Split the string into array with day, month and year strings with Split function
    2. get the date using the array cells with Date function
    3. use DateAdd function to add dates

    StringVar array datestr := Split({OperationHeader.ReceiptDate}, ".");
    
    DateAdd("d", {OperationDetails.GoodsPriceOut10}, Date(ToNumber(datestr[3]), ToNumber(datestr[2]), ToNumber(datestr[1])));