Round hour to 15 minutes

Hi, I want to display hour rounded to 15 min.

Example : 8:36 diplay 08:30, 8:40 display 08:45

Thanks

Subject: Round hour to 15 minutes

I don’t know of a simple “time rounding” function so you’ll probably have to extract the minutes and then check if the minutes fall within a certain range and then adjust the time accordingly. Using @functions, your formula might look something like this:

REM “round minutes to nearest quarter hour”;

time := TimeOut1;

min := @If(time = “”; @Return(“”); @Minute(time));

@If(min >= 0 & min <= 7; @Adjust(time; 0;0;0;0;-(min); 0);

min >= 8 & min <= 22; @Adjust(time; 0;0;0;0;-(min - 15); 0);

min >= 23 & min <= 37; @Adjust(time; 0;0;0;0;-(min - 30); 0);

min >= 38 & min <= 52; @Adjust(time; 0;0;0;0;-(min - 45); 0);

@Adjust(time; 0;0;0;0; -(min - 60); 0))

If you need to do this in LS, there are equivalent methods for @Minute and @Adjust.

Hope that helps.

Subject: Round hour to 15 minutes

basetime := @Now;minute := @Minute(basetime);

fullQuarters := @Integer(minute/15);

remainder := minute - (fullQuarters * 15);

adjust := @If(remainder < 8; 0; 15);

basetime : @Adjust(@Adjust(basetime;0;0;0;0;-minute;-@Second(basetime));0;0;0;0;(fullQuarters * 15) + adjust;0)

Use a field value for basedate if working from an existing value.

Subject: RE: Round hour to 15 minutes

This is great for setting the default value of a time field to the nearest 15 minute increment. You’ll want to tweak the formula slightly as Stan’s last line is a bit confusing:

basetime := @Now;

minute := @Minute(basetime);

fullQuarters := @Integer(minute/15);

remainder := minute - (fullQuarters * 15);

adjust := @If(remainder < 8; 0; 15);

adjustedtime := @Adjust(@Adjust(basetime;0;0;0;0;-minute;-@Second(basetime));0;0;0;0;(fullQuarters * 15) + adjust;0);

adjustedtime