Gustav Brock
Gustav at cactus.dk
Mon Jan 15 12:08:29 CST 2007
Hi John They look pretty efficient (fast) to me. We use these function which are a bit more flexible but I doubt they are faster: <code> Public Function DateWeekFirst( _ ByVal datDate As Date, _ Optional ByVal lngFirstDayOfWeek As Long = vbMonday) _ As Date ' Returns the first date of the week of datDate. ' lngFirstDayOfWeek defines the first weekday of the week. ' 2000-09-07. Cactus Data ApS. ' No special error handling. On Error Resume Next ' Validate lngFirstDayOfWeek. Select Case lngFirstDayOfWeek Case _ vbMonday, _ vbTuesday, _ vbWednesday, _ vbThursday, _ vbFriday, _ vbSaturday, _ vbSunday, _ vbUseSystemDayOfWeek Case Else lngFirstDayOfWeek = vbMonday End Select DateWeekFirst = DateAdd("d", vbSunday - WeekDay(datDate, lngFirstDayOfWeek), datDate) End Function Public Function DateWeekLast( _ ByVal datDate As Date, _ Optional ByVal lngFirstDayOfWeek As Long = vbMonday) _ As Date ' Returns the last date of the week of datDate. ' lngFirstDayOfWeek defines the first weekday of the week. ' 2000-09-07. Cactus Data ApS. ' No special error handling. On Error Resume Next ' Validate lngFirstDayOfWeek. Select Case lngFirstDayOfWeek Case _ vbMonday, _ vbTuesday, _ vbWednesday, _ vbThursday, _ vbFriday, _ vbSaturday, _ vbSunday, _ vbUseSystemDayOfWeek Case Else lngFirstDayOfWeek = vbMonday End Select DateWeekLast = DateAdd("d", vbSaturday - WeekDay(datDate, lngFirstDayOfWeek), datDate) End Function </code> /gustav >>> jwcolby at colbyconsulting.com 15-01-2007 18:57:38 >>> Has anyone got more efficient code than the following? Function DteFirstDayOfWeek(dte As Date) As Date Dim intDOW As Integer intDOW = Weekday(date, vbUseSystemDayOfWeek) DteFirstDayOfWeek = date - (intDOW - 1) End Function Function DteLastDayOfWeek(dte As Date) As Date Dim intDOW As Integer intDOW = Weekday(date, vbUseSystemDayOfWeek) DteLastDayOfWeek = date + (7 - intDOW) End Function John W. Colby Colby Consulting www.ColbyConsulting.com