Excel Feature Version:
As requested in the comments, only the excel function version is available here:
ROUND TO THE NEXT BORDER OF 15 MINUTES:
= TIME (HOUR (A1), 15 * CEILING (MINUTE (A1) / 15.1), 0)
- NB replace A1 with (t2-t1) according to the original question
ROUND TO THE NEAREST BORDER OF 15 MINUTES:
= TIME (HOUR (A1), 15 * ROUND (MINUTE (A1) / 15.0), 0)
btw: conversion to a string for date processing should be prevented, both for performance reasons and possibly also for geology reasons. Perhaps this is not so important to you.
VBA version
you can do this with div and mod functions. Not sure if you want it in vba or excel macros, but here is the approach. I donβt have right now, so here goes ...
(do in vba if you need to reuse it)
convert to fractions
d = gender (n / 0.25)
remainder = n mod 0.25
x = 0.25 * round (remainder / 0.25)
answer = (d * 0.25) + x
which should be close.
... just thought that the excel bond was ticking on a decimal function (which was again). This may be the best way.
encoded in vba ... only basic testing:
Public Function f(n As Double) As Double Dim d As Double, r As Double, x As Double d = Int(n / 0.25) r = n - (d * 0.25) ' strange... couldn't use mod function with decimal? x = 0.25 * Round(r / 0.25) f = (d * 0.25) + x End Function
USING:
(in the cell)
= F (c9-D9)
sgtz source share