|
|
SynopsisCalculate the date of the first day of the specified week.
This function is one of four (see also FirstDayOfCurrentWeek 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 a specific week. This UA post provides a more compact alternative to the code used in this function. CODE ' FirstDayOfWeek
' http://www.utteraccess.com/wiki/index.php/FirstDayOfWeek ' Code courtesy of UtterAccess Wiki ' Licensed under Creative Commons License ' http://creativecommons.org/licenses/by-sa/3.0/ ' ' 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 fFirstDayOfWeek(rDate As Date, rbytWeekStartsOn As Byte) As Date ' Procedure: fFirstDayOfWeek ' Description: return the date of the first day of the week in which ' the specified day occurs '-- Const cstrProcedure = "fFirstDayOfWeek" Dim intOffset As Integer Dim dtmResult As Date On Error GoTo HandleError intOffset = Weekday(rDate) - rbytWeekStartsOn If intOffset >= 0 Then dtmResult = rDate - intOffset Else 'dtmResult = rDate + 7 - intOffset dtmResult = Date - intOffset - 7 End If fFirstDayOfWeek = dtmResult HandleExit: Exit Function HandleError: 'insert custom error handler here 'ErrorHandle Err, Erl(), cstrModule & "." & cstrProcedure 'Resume HandleExit End Function
|
| This page was last modified 08:30, 6 April 2011. This page has been accessed 1,297 times. Disclaimers |