How to round off the value of time to the next 45 min

Hi Guys,

For example: If the current time is 7:02 PM, output should be 7.45 PM
if the current time is 7.16 PM , output should be 8:00 PM

Please let me know how to get the output. Thanks in advance!

Hi @vinutha1 ,
Try below code and implement the same logic in uipath

DateTime RoundUp(DateTime dt, TimeSpan d)
    return new DateTime((dt.Ticks + d.Ticks - 1) / d.Ticks * d.Ticks, dt.Kind);


var dt1 = RoundUp(DateTime.Parse("2011-08-11 16:59"), TimeSpan.FromMinutes(15));
// dt1 == {11/08/2011 17:00:00}

var dt2 = RoundUp(DateTime.Parse("2011-08-11 17:00"), TimeSpan.FromMinutes(15));
// dt2 == {11/08/2011 17:00:00}

var dt3 = RoundUp(DateTime.Parse("2011-08-11 17:01"), TimeSpan.FromMinutes(15));
// dt3 == {11/08/2011 17:15:00}


1 Like

Hi @vinutha1,

Try this also,

TimeRoundOff45.xaml (4.8 KB)


hi @kadiravan_kalidoss

Thank you for the solution…but i need to round off it to the 45mts exactly. because the drop down given in the application only i should pick.


give a try on (datetime based approach)

feel free to use any datetime variable instead of now representing a particular datetime like
yourvar.addMinutes(45 - (yourvar.Minute Mod 15)).toString(“h:mm tt”)



Thank you so much…its working for me correctly!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.