0

How to round time to 15 minutes

Hi all,

I'm pretty new to Ninox and I cannot find anything on how to properly round time to the nearest increment of, say, 15 minutes. Say I have a totaltime of 09:27 (from different time entries in a timesheet). Before doing any calculations with that total time amount I want this to be rounded to 09:30. When a totaltime is 09:18, it must be rounded to 09:15.

How to format a formula to get this done?

2 replies

null
    • toon
    • 5 yrs ago
    • Reported - view

    Ok, solved this by myself (woohoo!)

    To round time you have to work with a number, in this case milliseconds. After that you round that number by dividing it by 60000 (equals 1 minute) and then by 15 (the number of minutes you would like. For half an hour this number would be 30). After that, you have to convert the number into time again. It goes like this:

    let myHours := sum(Timesheet['Uren al gefactureerd?' = true].'Aantal uren');
    let myMilliseconds := number(myHours);
    let aantalKwartieren := round(myMilliseconds / 60000 / 15, 0);
    time(aantalKwartieren * 900000)

    The variable myHours in this case is 01:10, so the variable myMilliseconds is 4200000.
    The variable aantalKwartieren is 5. This is the number of times it can be divided in whole increments of 15 after it was divided by 60000.
    The last part of this formula takes the number 5 and multiplies that with 900000 (which is 15 minutes in millisecons).
    The result is a time of 01:15

    • DOM I.T. SERVICE GmbH
    • Stefan_Maiss
    • 5 yrs ago
    • Reported - view

    what about this, in one line:

     

    time(round(myHours / 3600000 * 4) * 3600000 / 4)

     

    ;-)

Content aside

  • 5 yrs agoLast active
  • 2Replies
  • 2111Views