start and end dates for week

Janet Thomas

Registered User.
Local time
Today, 23:09
Joined
Aug 15, 2002
Messages
20
On a form I need to display the actual date of the Sunday in the week 4 weeks from now and the Saturday in that week. For example, if today is 15 August, I want my form to display Start date= 09/08/02 and End date= 09/15/02. Tomorrow the form should display the same thing but next Monday it would display 09/16/02 and 09/22/02. Seems like I need to convert today's date to a weeknum, add 4, and then get the get start and end of that weeknum. Or perhaps I could convert today's date into a date with a 1 in the day number and and 4 weeks and do the same with the day number as 7. But I have no clue as to how to write this!
All help is appreciated!
 
Last edited:
The following functions get the last day of a week and the first day of a week. You just need to send through the date and first week day value, the first week day value defaults to whatever is set in your system settings, usually Sunday or Monday.

To get start and end for 4 weeks in advance then just use DateAdd function to add 4 weeks to current date like so
DateAdd("ww",4,Date())

The functions are from a database of samples available on microsoft.com, just search for neatcd97.mdb for the A97 version.

Code:
Function EndOfWeek(D As Variant, Optional FirstWeekday As Integer) As Variant
'
' Returns the date representing the last day of the current week.
'
' Arguments:
' D            = Date
' FirstWeekday = (Optional argument) Integer that represents the first
' day of the week (e.g., 1=Sun..7=Sat).
'
If IsMissing(FirstWeekday) Then 'Sunday is the assumed first day of week.
  EndOfWeek = D - WeekDay(D) + 7
Else
  EndOfWeek = D - WeekDay(D, FirstWeekday) + 7
End If
End Function

Function StartOfWeek(D As Variant, Optional FirstWeekday As Integer) As Variant
'
' Returns the date representing the first day of the current week.
'
' Arguments:
' D            = Date
' FirstWeekday = (Optional argument) Integer that represents the first
' day of the week (e.g., 1=Sun..7=Sat).
'
If IsMissing(FirstWeekday) Then 'Sunday is the assumed first day of week.
  StartOfWeek = D - WeekDay(D) + 1
Else
  StartOfWeek = D - WeekDay(D, FirstWeekday) + 1
End If
End Function
 

Users who are viewing this thread

Back
Top Bottom