Round the time to the nearest value

Hi the automation Team,

I am facing one issue to round off the time.

When I am running the bot, I have to look into 1 hour back for an example if I am running the bot at 14:25 I have to look the data 1 hour before so my bot should pick the data for 13:25. But I need to extract the data at 13:00, means I need to round the time to the fixed date instead of minutes.

Kindly help me on this

Thanks

Some parts are unclear form the description. Maybe you are looking for this:
grafik
Enhanced to the following, getting it work on day borders
grafik

You can round the time to the nearest fixed hour using the following code:

currentTime = currentTime.Date.AddHours(currentTime.Hour)

Finally, you can subtract one hour to get the time you want. using Following Code:

currentTime = currentTime.AddHours(-1)

Thanks For Quick Reply

I am using the below format

Now.ToString(“dd MMM yyyy”)+" "+DateTime.Now.AddHours(-1).ToString(“hh:mm tt”)

This will give me the format as 23 Oct 2023 02:09 PM so I need to round off this to 23 Oct 2023 02:00 PM

Thanks

when it is always about base lining it to 00
DateTime.Now.AddHours(-1).ToString("hh:00 tt")

But keep in mind:

when a 00:25 is also to handle it will be the day before for a right date calculation

Also have a look at this:

Assign Activity:
myDate = Now()

Assign Activity
myBaseDate = myDate.addHours(-1).AddMinutes(-myDate.Minute)

grafik

1 Like

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