Skip to main content
November 6, 2023
Question

Negative interval(day to second) to positive

  • November 6, 2023
  • 1 reply
  • 0 views

Hi Team,

I'm having a function which calculates the time difference between a date time( output of a rule) and now(). then applying hour() to find how many hours it differing. But incase I'm checking this at 06-11-2023 7:00 am(output of rule) and my current time is also today 7 am , it generating Interval (Day to second) in negative like  -0::00:06:37.727 due to millisecs difference, so while taking hour for this converting 0 hour to 23 . but what I need is  0::00:06:37.727. so that my hour difference calculation will return 0. Anyone know how to do the conversion or any better solution?


Thanks in advance

[mention:126a676c85024855948336691b0a7b92:e9ed411860ed4f2ba0265705b8793d05]

    1 reply

    stefanhelzle0001
    Brainy
    November 6, 2023

    In Appian, the difference between two dates is called an interval. Intervals are stored as decimals internally. This means, you can use the abs() function to get the positive value.

    Some example code below:

    a!localVariables(
      local!firstDate: datetime(2023, 11, 6, 7, 0, 0, 0),
      local!secondDate: datetime(2023, 11, 6, 7, 1, 0, 0),
    
      tointervalds(
        abs(
          todecimal(local!secondDate - local!firstDate)
        )
      )
    )