Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Function to Get Date of Monday Prior to Current Day


View products that this article applies to.

This article was previously published under Q210498
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


Summary

This article describes a function that you can use to find the date of the Monday prior to the current day.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

↑ Back to the top


More information

The following function determines Monday's date according to the following criteria:
  1. If the current date is Tuesday through Sunday, it yields the date of the prior Monday.
  2. If the current day is Monday, it returns the current date.
  3. If the date is Null or is not a valid date, it returns Null.
To create this function, follow these steps:
  1. Create a module and type the following line in the Declarations section if it is not already there:
    Option Explicit
  2. Type the following procedure:
    Function GetMonDate(CurrentDate)
       If VarType(CurrentDate) <> 7 Then
          GetMonDate = Null
       Else
          Select Case Weekday(CurrentDate)
             Case 1       ' Sunday
                GetMonDate = CurrentDate - 6
             Case 2       ' Monday
                GetMonDate = CurrentDate
             Case 3 To 7  ' Tuesday..Saturday
                GetMonDate = CurrentDate - Weekday(CurrentDate) + 2
           End Select
       End If
    End Function
To test the function, type the following line in the Immediate window, and then press ENTER:
? GetMonDate(#4/30/93#)
Note that the following result will be displayed in the Immediate window:
   #4/26/93#

↑ Back to the top


Keywords: KB210498, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 210498
Revision : 4
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 356