Calculate the date of the first day of the current week.
This function is one of four (see also FirstDayOfWeek LastDayOfCurrentWeek LastDayOfWeek ) that can be used to calculate the beginning or ending date of seven day week. A typical use would be in an invoicing/collections application that requires reporting on outstanding invoices that will reach a certain age in days sometime during the current week. This UA post provides a more compact alternative to the code used in this function.
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev date brief descripton
' 1.1 2011-02-19 else clause modified
Public Function fFirstDayOfCurrentWeek(rbytWeekStartsOn As Byte) As Date
' Procedure: fFirstDayOfCurrentWeek
' Description:return the date of the first day of the week in which
' the current day occurs
Const cstrProcedure = "fFirstDayOfCurrentWeek"
Dim intOffset As Integer
Dim dtmResult As Date
On Error GoTo HandleError
intOffset = Weekday(Date) - rbytWeekStartsOn
If intOffset >= 0 Then
dtmResult = Date - intOffset
'dtmResult = rDate + 7 - intOffset
dtmResult = Date - intOffset - 7
fFirstDayOfCurrentWeek = dtmResult
'insert custom error handler here
' ErrorHandle Err, Erl(), cstrModule & "." & cstrProcedure
' Resume HandleExit
|This page has been accessed 2,732 times. This page was last modified 08:29, 6 April 2011 by Jack Leach. Contributions by Glenn Lloyd Disclaimers|