Round now() time to the earliest hour

I need to round the current time (now()) to the earliest hour

In Excel I use the following:

FLOOR(H4,1/24)

In UiPath, if I tried:

math.Floor(now.ToOADate,1/24).ToString

But it doesn’t work as it doesn’t accept the “1/24” significance parameter

Any ideas on how to do it in UiPath?

Playing around with the functions I managed to resolve it. Here it is in case it helps someone:

cdate(date.FromOADate((math.Floor(now.ToOADate *24))/24)).ToString

A couple ways you can do this. The most straightforward way would be to convert it to a string, then use datetime.parseexact to convert your newly created string back into datetime. So it would be

(type = string) Assign NowAsString = now.tostring(“dd/mm/yyyy HH”)
(type = datetime) Assign YourRoundedDate = Datetime.ParseExact(NowAsString,“dd/mm/yyyy HH”,CultureInfo.InvariantCulture)

1 Like

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