Date Calculations (2 Viewers)

sznsx

Registered User.
Local time
Today, 08:09
Joined
Jul 25, 2004
Messages
20
Hello All ! :confused:

When given a specific weekday date, I need to determine the dates of the rest of weekdays within that current week. All I need is Mon, Tues, Wed, Thurs, Fri, I do not care about saturday or sunday.

Example 1:
Given date 7/27/2004 (which is a tuesday)
I would like to know that the following weekdays are part of that given week:
7/26/2004, 7/28/2004, 7/29/2004, 7/30/2004

Just to give you the idea, another example...

Example 2:
Given date 5/19/2004 (which is a wednesday)
I would like to know that the following weekdays are part of that given week:
5/17/2004, 5/18/2004, 5/20/2004, 5/21/2004
 

raskew

AWF VIP
Local time
Today, 07:09
Joined
Jun 2, 2001
Messages
2,734
Function GetStartDate returns the first day of a week based
on a date input by user and a starting weekday. With this
you set a date field's criteria to
Between GetStartDate([enter a date]) and GetStartDate([enter a date])+6
Code:
Function GetStartDate(dteMyDate As Date, _
                      Optional pDay As Integer = 2) As Date
'*******************************************
'Purpose:       Return the first day of a week
'               based on a date input by user
'               and a starting weekday (pDay)
'Coded by:      raskew
'Parameters:    dteMyDate: the target date
'               pDay: Day of week of starting day [Sun(1) - Sat(7)]
'Inputs:        from the debug window:
'               ? GetStartDate(#2/22/03#, 4)
'Output:        2/19/03
'*******************************************
Dim StartDate As Date

    pDay = IIf(IsMissing(pDay), 2, pDay)
    If WeekDay(dteMyDate) = pDay Then
       StartDate = dteMyDate
    Else
       StartDate = dteMyDate - (WeekDay(dteMyDate) + _
                   IIf(WeekDay(dteMyDate) <= pDay, 7, 0) - pDay)
    End If
    
    GetStartDate = StartDate
    
End Function
HTH - Bob
 

sznsx

Registered User.
Local time
Today, 08:09
Joined
Jul 25, 2004
Messages
20
Nice

Thanks for the help, I am working it out right now !!
 

Users who are viewing this thread

Top Bottom