Announcement

Collapse
No announcement yet.

Time Difference Question With Rounding

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Time Difference Question With Rounding

    Good Afternoon Everyone.

    I'm trying to figure a issue with the time difference formula. So our use case is we've built a time clock application where our employees walk in, enter their pin # and press a clock in button which create a time sheet record with the clock in time. Same concept for clocking out except it updates that same record with a clock out entry in the clock out field. Our issue is the way espo is rounding these times. For example


    Clock in Time:
    12/02/2021 06:21 AM
    Clock Out Time:
    12/02/2021 04:22 PM

    It generates 10 for total hours worked using the below formula. However it should technically be 10.02.

    $totalWorkedHours=datetime\diff(clockOutTime, clockInTime, 'minutes');
    $roundedWorkHours=$totalWorkedHours/60;
    totalWorkedHours=number\round($roundedWorkHours, 2);

    Does anyone know of a solution to this issue?

  • #2
    Hi Dom,

    This is probably something I would look into using in the future. Not sure of a solution here except for "Let Maths" it; my suggestion is to do this two time and see how EspoCRM store the value then math it from there?

    Test 1
    12/02/2021 06:21 AM
    12/02/2021 06:42 AM

    Test 2
    12/02/2021 06:21 AM
    12/02/2021 07:21 AM

    Test 3
    12/02/2021 06:21 AM
    12/02/2021 07:41 AM

    I remember having a similar issue when calculating time in Spreadsheet Excel and end up finding out I either have to convert the time to a Minutes unit then reconvert it back to an Hours:Minutes time. Perhaps a similar approach (might potentially) work.

    Comment

    Working...
    X