Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Calculating Days Between two dates

edited September 2005 in General
I wish to calculate the number of days between two dates in my report code
to populate a variable.

It seems that the function DaysBetween is not recognised in the application.

Has anyone been able to calculate the number of days between two dates and
if so how??
thanks
Sue

Comments

  • edited September 2005
    Hi Sue,

    Unfortunately RAP does not support the Delphi DaysBetween routine. In order
    to access this functionality in RAP, you can create a pass-thru function.
    Below is an example of a pass-thur function given by another customer that
    does just that. Hope it helps.

    ---
    Add the following to the interface section of the unit:

    type
    TraReturnDaysBetweenDates = class(TraSystemFunction)
    public
    class function Category: string; override;
    procedure ExecuteFunction(aParams: TraParamList); override;
    class function GetSignature: string; override;
    class function HasParams: Boolean; override;
    class function IsFunction: Boolean; override;
    end;

    Add the following the implemenation section of the unit:

    {
    ************************** TraReturnDaysBetweenDates
    ***************************
    }
    class function TraReturnDaysBetweenDates.Category: string;
    begin
    Result:= 'DateTime'
    end;

    procedure TraReturnDaysBetweenDates.ExecuteFunction(aParams: TraParamList);
    var
    iResult: Integer;
    Date1: TDateTime;
    Date2: TDateTime;
    begin
    GetParamValue(0, Date1);
    GetParamValue(1, Date2);

    iResult:= ReturnDaysBetweenDates(Date1,Date2);

    { The return value is the last value in the zero based parameter list }
    SetParamValue(2, iResult);
    end;

    class function TraReturnDaysBetweenDates.GetSignature: string;
    begin
    result := 'function ReturnDaysBetweenDates(Date1, Date2: TDateTime):
    Integer;';
    end;

    class function TraReturnDaysBetweenDates.HasParams: Boolean;
    begin
    Result:= True;
    end;

    class function TraReturnDaysBetweenDates.IsFunction: Boolean;
    begin
    Result:= True;
    end;

    Add the following to the initialization section of the unit:

    raRegisterFunction('ReturnDaysBetweenDates', TraReturnDaysBetweenDates);


    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.