Options

Time calculation

ArhontisArhontis Member Posts: 667
Hello everyone,

I have a field, or variable of type TIME and a decimal variable.

I want to add these two but cannot! :(

i.e. give the values:
varTime -> 13:00:00
Decimal -> 2,5
and get the result:
  varTime + Decimal -> 15:30:00
I tried making a time var (varTime2) with the decimal and execute:
varTime := varTime + varTime2;
but only subtraction is allowed (compiler error) between time variables, not addition!!

Anyone has done this before?

Comments

  • Options
    fbfb Member Posts: 246
    Section 19.2 of the Application designers guide indicates that addition of a decimal and a time variable is allowed with the following notes:
    • The operation is not defined for the time 0T
    • Overflow may occur
    • The operation is not defined if the decimal has a fractional part
    Since a C/AL TIME variable can be thought of (is internally stored as) as an integer containing 1 plus the # of milliseconds from midnight, and adding an integer to a time gives a new time integer milliseconds later, you can achieve your result as follows:
    varTime := varTime + ROUND(Decimal * 60 * 60 * 1000,1);
    
  • Options
    ArhontisArhontis Member Posts: 667
    I have studied the adg pdf before, but I didn't remember that it had such info...

    Thank you fb, it worked fine, even with fraction!!

    :D
Sign In or Register to comment.