3 Replies Latest reply on May 17, 2013 7:13 AM by philmodjunk

    Setting a field to the nearest 15min



      Setting a field to the nearest 15min


           Hi There,


           I need to find out what would be the best method for calculating a field to the nearest 15min. Im working on a clock in system. I was thinking of having a button that the user presses and it can get current time. That is the easy part. What I would like to be able to do is convert that time down to the nearest 15min. So if they press the button at 7:10 the time captured would be 7:00. 


           Would I need to use a case statement  along the lines? I have an idea that the logic behind the case would be something along the lines of,


           Min(Time) < 15; Min(Time) = 00;

           Min(Time) < 30; Min(Time) = 15;

           Min(Time) < 45; Min(Time) = 30;

           Min(Time) = 45


           I tried this calculation but it doesn't quite work :$

        • 1. Re: Setting a field to the nearest 15min



                 min($time) < 15 ; $closest15 = 0;

                15 < min($time) < 30 ; $closest15 = 15;


               $time to save = time(hour($time) ; $closest15 ; 0)

               This will work as script steps, but can redone to a calculation with the Let function. And of course you need all four minutes, this was just to give you the idea not do the work for you. ;)

          • 2. Re: Setting a field to the nearest 15min

                 Thank-you for the help. I want to get it working in a calculation field for time in and out but I have trouble with the Let funciton. For the TimeIn field, on the layout it is set to get(currenttime) when pressed, then I was thinking of making TimeIn a calculation field. Where am I going wrong in the calculation: 


                 $Time = get(currenttime);
                 $closest = 0;
                 Minute($Time) < 15; $closest= 0;
                 15 ≤ Minute($Time) < 30; $closest = 15;
                 30 ≤ Minute($Time) < 45; $closest= 30;
                 $closest = 45
                 TimeIn = time($time;$closest;0)
            • 3. Re: Setting a field to the nearest 15min

                   I suggest searching the Knowledge Base (see link at top of page). There's an article in there somewheres that documents a calculation for rounding to the nearest 15 minutes in an elapsed time calculation.

                   If you use a calculation field to capture the current time, make it unstored and do not try to set up a field of type time with an auto-enter calc to do it.