Home RAP

Date calculation

edited May 2011 in RAP
I have an end-user report, and am trying to create a OnCalc for a
user-defined variable that will take a date from the data (InvoiceDueDate)
and calculate how many days old that is as of today and display the result
on the report.

For example if the InvoiceDueDate is 05/01/2011, and "today" is 05/06/2011
the answer is 5 days old.

I created a variable, made it integer type, but have no clue what to put in
after the Value = : statement.

I could not find date manipilation examples in help, nor the newsgroup for
RAP.

Thanks in advance.

Comments

  • edited May 2011
    Hi Diana,

    I believe Delphi has a DaysBetween routine that takes two TDateTime
    parameters and returns an integer value built-in. Though this routine
    is not available in RAP, it would be easy to create a pass-thru function
    to add the functionality.

    See the main RAP demo located in the \Demos\0. RAP\... directory and the
    Developer's Guide for examples of creating pass-thru functions for RAP.

    Value := DaysBetween(DataSet['InvoiceDueDate'], Now);


    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2011
    Hi Nico,
    Thank you for your quick repsonse.

    While that is helpful, may I suggest that a function be available in a
    future release of RAP to enable the capability for a calculation of
    "DaysBetween"?

    The solution you present is terrific, but I have to wait for the next
    release of our software product to share that functionality with our client
    base. With the power of RAP we are able to customize many of our end-user
    reports without effecting the overall product release schedules (and all
    that goes along with the distribution of a new software release).

    Please add this request to the RAP enhancement "wish list" for a future
    release.

    Many Thanks!

  • edited May 2011
    Hi Diana,

    Thanks for the feedback. I will add this as a possible enhancement for
    a later release.

    Another option as a work-around would be to calculate the Days Between
    value manually in RAP. TDateTime values are Doubles describing the days
    and time (the whole number is the day and the decimal is the time). You
    could create a simple RAP routine that subtracts the larger date from
    the smaller and truncates the decimal to give you the days between.

    Pseudo Code...

    function DaysBetween(aNow, aThen: TDateTime): Integer
    begin
    if aNow < aThen then
    Result := Trunc(aThen - aNow)
    else
    Result := Trunc(aNow - aThen);
    end;


    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.