Hello Guys

I hope you are well

I have to round these times to nice numbers:

If its 13 becomes 15, to nearest quarter.

I can read the text and convert it to integer and split it to minutes, and hour.

How to round please help?

Do i have to use 100 if statements?

Thank You

ppr
(Peter Preuss)
2
one of many approaches

one question left: do you also looking for down rounding, like 15:17 → 15:15?

1 Like

Thank You Peter.

I am looking for:

08:13 → 08.15

14:17 → 14:15

19:29 → 19:30

13:24 → 13:25

Hi Hurmet,

how about this:

`MinutesRoundedToQuarter (Type Double) = Math.Ceiling(SampleMinutes / 15) * 15`

OH! You want to round down too…

`MinutesRoundedToQuarter (Type Double) = Math.Round(SampleMinutes / 15) * 15`

Lukas

Perfect.

Now I have to check if its 60 then add one more to the time.

if i have 19:34

How can i substring “9”

Thank You Lukaszie

ppr
(Peter Preuss)
6
have a look on my samples as this was exactly handling tem 60 min case und jumps up to next hour

1 Like

Oh what, wait. That’s not good.

You should use DateTime.AddMinutes instead then! No more time right now, I’ll try later

1 Like

I am looking also for down …

When its 18:11 should be 18:10

Thank You

ppr
(Peter Preuss)
9
combine the approach from Lukasz and mine. Just give me a little time

1 Like

ppr
(Peter Preuss)
10
2 Likes

Thank You Peter

I will test it now

Regards

Hurmet

I am looking for 5 minutes segment.

11 becomes 10

14 becomes 15

27 becomes 25

32 becomes 30

Thank You

ppr
(Peter Preuss)
13
so you are looking for a round to the closest 5 segement and not 15?

tsInit.AddMinutes(- tsInit.Minute).AddMinutes(Math.Round(tsInit.Minute / 5) * 5).toString(“HH:mm”)

3 Likes

This works. I changed 15 to 5 and it works.

Thank You MAN!

Only thing is how to convert “08:30” string to date?

I had to finish this

`RoundedTime = SampleTime.AddMinutes((Math.Round(SampleTime.Minute / MinuteInterval ) * MinuteInterval) - SampleTime.Minute)`

You can convert strings to dates a number of ways. Lots of examples in the forum. Here is one:

`SampleDateTime = DateTime.ParseExact(SampleString,"HH:mm",CultureInfo.InvariantCulture)`

Cheers,

Lukas

3 Likes

You are correct, this Works

THANK YOU SIR

All the best

1 Like

system
(system)
Closed
20
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.