Skip to main content
Known Participant
July 26, 2024
Question

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

  • July 26, 2024
  • 5 replies
  • 9 views

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
    July 26, 2024

    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
    July 26, 2024

    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
    Brainy
    July 26, 2024

    You could try using the calworkhours function.

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

    rupaa0642Author
    Known Participant
    July 26, 2024

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

    venkatrea696188
    Inspiring
    July 26, 2024

    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)
    )