Select Max(SomeField) From YourTable
Group By DateRound([TimestampField], 0, 0, 10)
Public Function DateRound( _
ByVal datDate As Date, _
Optional ByVal intHours As Integer, _
Optional ByVal intMinutes As Integer, _
Optional ByVal intSeconds As Integer) _
As Date
' Rounds datDate to hours and/or minutes and/or seconds as
' specified in parameters intHours, intMinutes, and intSeconds.
'
' Will accept any value within the range of data type Date:
'
' From 100-01-01 00:00:00 to 9999-12-31 23:59:59
'
' In case the range is exceeded due to rounding, the min. or max.
' value will be returned.
'
' Examples:
' DateRound(#9999-12-31 23:57:50#,0,5,0)
' returns: 9999-12-31 23:59:59
' DateRound(#9999-12-31 23:57:10#,0,5,0)
' returns: 9999-12-31 23:55:00
' DateRound(#9999-12-30 22:57:50#,0,5,0)
' returns: 9999-12-30 23:00:00
' DateRound(#2015-02-28 12:37:50#,0,15,0)
' returns: 2015-02-28 12:45:00
' DateRound(#2015-05-05 11:27:52#,3,0,0)
' returns: 2015-05-05 12:00:00
' DateRound(#2015-05-25 11:11:13#,0,0,2)
' returns: 2015-05-25 11:11:14
'
' Round to the tenth of a day:
' DateRound(#2012-11-15 15:00:00#, 2, 24, 0)
' returns: 2012-11-15 14:24:00
'
' 2008-04-16. Gustav Brock, Cactus Data ApS, CPH.
' 2010-05-12. Modified CDate expression.
Dim datRounding As Date
On Error GoTo Err_DateRound
datRounding = TimeSerial(intHours, intMinutes, intSeconds)
If datRounding <= 0 Then
' Round to the second.
datRounding = TimeSerial(0, 0, 1)
End If
' Apply CDec to prevent rounding errors from Doubles and allow large values.
datDate = CDate(Int(CDec(datDate) / CDec(datRounding) + 0.5) * datRounding)
Exit_DateRound:
DateRound = datDate
Exit Function
Err_DateRound:
If datDate < 0 Then
datDate = #1/1/100#
Else
datDate = #12/31/9999 11:59:59 PM#
End If
Resume Exit_DateRound
End Function
/gustav