Skip to main content
Known Participant
Jul 26, 2024 10:34 AM UTC
Question

Function to get the number of hours between two date and time

Hello All,

We need to calculate number of hours between two date and time values. and this should not consider weekends.

Thanks in advance

    5 replies

    stefanhelzle0001
    Brainy
    Jul 26, 2024 10:53 AM UTC

    Just subtract the two dates. It will return an interval. That format is a bit weird, but you will find enough coding examples to parse it here.

    a!localVariables(
      local!interval: split(userdatetime(2024,7,26,1,1,1) - userdatetime(2024,7,20,3,3,3), ":"),
      local!interval[1]*24 + local!interval[3]
    )

    rupaa0642Author
    Known Participant
    Jul 26, 2024 11:02 AM UTC

    Thank you Stephen. But it should not consider weekend hours.

    Eg: Start Date time : 07/26/2024 11:00AM

          End Date time : 07/29/2024 11:00AM

    should give us 24 hours. It should ignore weekend hours.

    mathieud0001
    Genius
    Jul 26, 2024 11:02 AM UTC

    You could try using the calworkhours function.

    docs.appian.com/.../fnc_date_and_time_calworkhours.html

    rupaa0642Author
    Known Participant
    Jul 26, 2024 11:03 AM UTC

    Thank you mathieud0001,  this considers only week hours. But my use case is only not to consider weekend hours.

    venkatrea696188
    Inspiring
    Jul 26, 2024 12:08 PM UTC

    If so , Use Stefan's  logic ,but somehow you need to find out how many weekdays are there or In default working calendar weekends are considered non working days , So use calworkingdays() .

    a!localVariables(
    local!workdays:calworkdays(ri!startTime,ri!endTime-1),
    (hour(ri!endTime-ri!startTime)+local!workdays*24)
    )