UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> LastDayOfCurrentWeek    


Calculate the date of the last day of the current week. This function is one of four (see also FirstDayOfCurrentWeek FirstDayOfWeek 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 particular week. This UA post provides a more compact alternative to the code used in this function.

' LastDayOfCurrentWeek
' http://www.utteraccess.com/wiki/LastDayOfCurrentWeek
' 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 fLastDayOfCurrentWeek(rbytWeekEndsOn As Byte) As Date
' Procedure: fLastDayOfCurrentWeek
' Description: return the date of the last day of the week in which
'              the current day occurs

   Const cstrProcedure = "fLastDayOfCurrentWeek"
   Dim intOffset As Integer
   Dim dtmResult As Date
   On Error GoTo HandleError

   intOffset = rbytWeekEndsOn - Weekday(Date)

   If intOffset >= 0 Then
       dtmResult = Date + intOffset
       'dtmResult = Date + 7 + (rbytWeekEndsOn - Weekday(Date))
       dtmResult = Date + 7 + intOffset
   End If

   fLastDayOfCurrentWeek = dtmResult


   Exit Function

   'insert error handler here
   'ErrorHandle Err, Erl(), cstrModule & "." & cstrProcedure
   'Resume HandleExit

End Function

Creative Commons License
LastDayOfCurrentWeek by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 7,662 times.  This page was last modified 08:51, 6 April 2011 by Jack Leach. Contributions by Glenn Lloyd  Disclaimers