How to round time to the nearest quarter hour

I am using a time widget i need to set the time on load to nearest quarter hour. for example if current time 10:43, i need to set to 10:40 or even 10:45. How do we do this in outsystems.

Hello prashanth,

I don't think there is anything "ready" for this.

But you could use the Minute builtin action to retrieve the "minute part", round it using logic and then build the time again using the NewTime builtin action.

Cheers.

Solution

prashanth ms,

Let's say your old datetime value is in OldTime variable.

New time rounded to nearest quater can be calculated the following way:

NewMinute = Round(Minute(OldTime)/15) * 15;

NewTime(Mod(Hour(OldTime) + Trunc(NewMinute/60), 24), Mod(NewMinute, 60))

Solution

Eduardo Jauch wrote:

Hello prashanth,

I don't think there is anything "ready" for this.

But you could use the Minute builtin action to retrieve the "minute part", round it using logic and then build the time again using the NewTime builtin action.

Cheers.

thanks. 


Vitaly Martynenko wrote:

prashanth ms,

Let's say your old datetime value is in OldTime variable.

New time rounded to nearest quater can be calculated the following way:

NewMinute = Round(Minute(OldTime)/15) * 15;

NewTime(Mod(Hour(OldTime) + Trunc(NewMinute/60), 24), Mod(NewMinute, 60))

thanks for this quick work around logic.