Calculate with date-time fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • animax
    Senior Member
    • Jun 2018
    • 172

    #1

    Calculate with date-time fields

    hi,

    I have two "date-time" fields in the entity. One field is the start time in the format "dd.mm.yyyy hh:mm" and one field is the end time field, also in the format "dd.mm.yyyy hh:mm."
    I need the minutes between the end time and the start time in one field.
    Example:
    Start time 10/14/2025 3:00 PM
    End time 10/14/2025 3:15 PM
    Result: 15 (minutes)
    and after that i would prefer to show the hours, like 0,25 (15 minutes)

    I've already looked in the forums, but haven't found anything suitable. The diff function didn't work the way I did it.

    How do I get the minutes?

    In the german Excel Version, the function is:
    =RUNDEN((B7-A7)*24;2)
    Example:
    Click image for larger version

Name:	image.png
Views:	0
Size:	3.9 KB
ID:	122144

    Thank you
    Last edited by animax; 10-14-2025, 01:43 PM.
  • lazovic
    Super Moderator
    • Jan 2022
    • 1181

    #2
    Hi animax,

    Please use the following formula script example:
    Code:
    $dateA = '2025-07-08 12:30:11';
    $dateB = '2025-07-08 12:45:11';
    
    $minDiff = datetime\diff($dateB, $dateA, 'minutes');
    $hoursDiff = number\round($minDiff / 60, 2);
    
    output\printLine($hoursDiff);
    Output: 0.25

    Comment


    • animax
      animax commented
      Editing a comment
      Thank you...

      I use a floating-point variable to store the result. The variable is called "zeitberechnung"

      My start time is called "StartTime," and my end time is called "EndTime."

      I tried to adopt it, but it doesn't work; I'm not a professional. Could you rewrite the script for me? Is floating point number for the result correct?
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1761

    #3
    The formula would be:

    minuten = datetime\diff(ende, beginn, 'minutes')

    You calculate the minutes between start and end, here also in german. 'minutes' is in english, because it makes part of the formula.

    Comment

    • lazovic
      Super Moderator
      • Jan 2022
      • 1181

      #4
      animax,

      Please try using this formula script:
      Code:
      $minDiff = datetime\diff(endTime, startTime, 'minutes');
      zeitberechnung = number\round($minDiff / 60, 2);

      Comment

      • animax
        Senior Member
        • Jun 2018
        • 172

        #5
        Thank you very much! Thats it! Perfect!

        Comment

        Working...