# Math function (for use in PS script) to determine exact 5 minute intervals starting at top of the hour

• ### Question

• This is more of a math question than PS, but I am wondering if anyone has seen or created a math function that will determine the next 5 minute time slice from starting at the top of the last hour.  Not sure how to explain what I need (which has made searching for this with Google difficult), but let me give an example:

If the time is 1:03 PM, I want a math function to spit out 1:05 PM (not 1:08 PM, which is 5 minutes from the current time)

If the time is 1:48 PM, I want that math function to spit out 1:50 PM (not 1:53 PM)

If you could provide this in PS format, that would be best - but if not, even if you could provide the math technique to figure this out, I can convert it to PS myself.

Thanks

NK

Monday, September 29, 2014 6:06 PM

• Something like this, perhaps?

```\$minuteIncrement = 5
\$dt = get-date
\$minutesToAdd = \$minuteIncrement - (\$dt.Minute % \$minuteIncrement)
```

-- Bill Stewart [Bill_Stewart]

• Marked as answer by Monday, September 29, 2014 6:29 PM
Monday, September 29, 2014 6:24 PM

### All replies

• Something like this, perhaps?

```\$minuteIncrement = 5
\$dt = get-date
\$minutesToAdd = \$minuteIncrement - (\$dt.Minute % \$minuteIncrement)
```

-- Bill Stewart [Bill_Stewart]

• Marked as answer by Monday, September 29, 2014 6:29 PM
Monday, September 29, 2014 6:24 PM
• While this probably isn't the cleanest or best way, it's one way.

```function get-next-five-minute-span(\$time) {
\$match =@('00','05','10','15','20','25','30','35','40','45','50','55')

do {
if ( \$match.Contains([string](get-date(\$time) -Format mm)) ){
break
} else {
}
} while (\$true)
return \$time
}```

Monday, September 29, 2014 6:27 PM
• Thank you sir - that works perfect!

NK

Monday, September 29, 2014 6:30 PM
• Thank you!.  Going to go with Bills suggestion as it is a bit cleaner - but I appreciate you taking the time to offer your solution.

NK

Monday, September 29, 2014 6:30 PM