|
|
|
For reporting, many times you need to figure out what date last week began and ended. Use the code below to figure that out: |
Click here to copy the following block | Dim vntBegin As variant Dim vntEnd As variant Const constSunday As Integer = 1 GetPriorWorkWeek BeginDayOfWeek:=constSunday, WeekBegin:=vntBegin, _ WeekEnd:=vntEnd Print "Begin of Week: " & vtnBegin & ", End of Week: " & vtnEnd
This is the complete code of the GetPriorWorkWeek routine. You can easily modify it to work with any date passed as an argument, not just the current system date:
Sub GetPriorWorkWeek(ByVal BeginDayOfWeek As Integer, Optional ByVal WeekBegin _ As Variant, Optional ByVal WeekEnd As Variant)
Dim dteDate As Date Dim blnFound As Boolean
If BeginDayOfWeek < 1 Or BeginDayOfWeek > 7 Then Err.Raise Number:=1000, Source:="GetLastDayOfMonth", _ Description:="Invalid BeginDayOfWeek, must be between 1 and 7" End If
dteDate = DateAdd("d", -7, Now)
Do Until blnFound If Weekday(dteDate) = BeginDayOfWeek Then WeekBegin = dteDate blnFound = True Else dteDate = DateAdd("d", -1, dteDate) End If Loop
WeekEnd = DateAdd("d", 6, WeekBegin)
End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|