Is there a function or procedure to round to the nearest hour. For example, if I had 1-Jan-2002 23:23:59 it would return 1-Jan-2002 23:00:00. Any help would be appreciated.
As foada says, it is not entirely clear what you want. If all you need is the hour part of the time, then his example is probably the simplest way of getting it. If, on the other hand, you want to convert a whole date value to the nearest hour, something like this might be appropriate (based on the fact that a date is actually held as a floating point number, the decimal portion of which represents how many 1/24 of a day have passed): [tt]
Private Function NearestHour(tTime As Date) As Date
NearestHour = Fix(tTime) + (((tTime - Fix(tTime)) * 24) Mod 24) / 24
End Function [/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.