SAP Knowledge Base Article - Public

3838177 - Difference between two time fields in leave request

Symptom

  • A business rule is required to calculate the difference between custom Start Time and End Time fields in SAP SuccessFactors Time Off.
  • The system does not correctly validate the time difference against the requested permission hours when submitting an absence request.
  • The expected validation error is not triggered when the duration calculated from the Start Time and End Time fields exceeds the requested permission hours.
  • An error occurs when attempting to calculate the difference between two time fields using a business rule.

Business Requirement

The requirement is to validate the duration between the employee's Start Time and End Time against the requested permission hours.

For example:

  • If an employee requests 5 hours and enters a Start Time of 09:00 AM and an End Time of 01:00 PM, the system should allow submission because the entered time difference is 4 hours, which is less than the requested 5 hours.
  • If an employee requests 4 hours and enters a Start Time of 09:00 AM and an End Time of 03:00 PM, the system should trigger a validation error and prevent submission because the entered time difference is 6 hours, which exceeds the requested 4 hours.

Image/data in this KBA is from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental.

Environment

  • SAP SuccessFactors Employee Central – Time Management

Reproducing the Issue

  1. Navigate to the Create Absence UI.
  2. Select a duration-based Time Type.
  3. Enter the requested permission hours.
  4. Populate the custom Start Time and End Time fields.
  5. Submit the absence request.
  6. Observe that the expected validation error is not triggered when the time difference exceeds the requested permission hours.

Resolution

Use the business rule function "Calculate Duration in Seconds Between Two DateTime Values()" to calculate the difference between the Start Time and End Time fields.

Since the function returns the duration in seconds, divide the result by 3600 to convert the duration into hours.

Business Rule Configuration

Use the following calculation:

Employee Time.Fraction Quantity < Duration in Seconds / 3600

Configure the rule function as follows:

Function: Divide()

  • Dividend: Calculate Duration in Seconds Between Two DateTime Values()
    • First DateTime: Create DateTime()
      • Local Date: Employee Time Start Date
      • Local Time: Employee Time Custom Start Time
    • Second DateTime: Create DateTime()
      • Local Date: Employee Time Start Date
      • Local Time: Employee Time Custom End Time
  • Divisor: 3600

The divisor of 3600 converts seconds into hours because one hour contains 60 × 60 = 3600 seconds.

Use the calculated duration to compare the actual time difference against the requested permission hours and configure the appropriate validation condition.

Keywords

SAP SuccessFactors Time Off, Calculate Time Difference, Start Time and End Time, Calculate Duration in Hours, Calculate Duration in Seconds Between Two DateTime Values, Business Rule Error, Time Off Business Rule, Duration-Based Time Type, Permission Hours Validation, Validate Start and End Time, Employee Time Fraction Quantity, Divide Function, Create DateTime Function, Custom Time Fields, Absence Request Validation, Time Difference Calculation, Convert Seconds to Hours, Time Off Validation Rule, Requested Hours vs Actual Hours, Prevent Absence Submission, Employee Central Business rules, business requirement, How to calculate the difference between start time and end time, how to calculate the hours difference between start time and end time, how to calculate the difference in time, seconds to hours, convert seconds to hours, convert seconds to minute, Take rule. , KBA , LOD-SF-EC-TIM-RUL , TAT Rules, Validation & Take rules , How To

Product

SAP SuccessFactors HCM Core 2605