I have a table of call data with timestamps such as: 12:07:14 PM, and wish to translate that in my query to a corresponding 1/2 hour interval. So for each record in the query results, I should be able to see both: 12:07:14 PM and 12:00 PM.
It is a bit more complex to do normal rounding by splitting the parts like this because the the hours are affected by the minutes rounding. An alternative is to round the time itself.
Code:
CDate(Round([timestamp]*48)/48)
Round down with this expression:
Code:
CDate(Int([timestamp]*48)/48)
The problem with this technique is rounding error because half hours don't always come out exactly as decimal parts of a day. Consequently you may find parts of a second included. These can become a problem when you compare times.
This is why imes should always be compared using DateDiff(). However because the rounded times are derived very differently from times entered directly so it is possible that DateDiff() may still have problem.
One of the other techniques can then be applied to these results to get the results into line.
Also note that Round() uses Bankers Rounding where values exactly in the middle will round to the even whole number.
Thanks for your response/advice. I need it rounded down. I am going to try to implement something you've stated here, but as I'm new, I may end up with more questions. Lol.