# Thread: How to get this week's beginning and ending dates ...

1. Grand Poobah
Join Date
Sep 2003
Location
MI
Posts
3,713

## Unanswered: How to get this week's beginning and ending dates ...

Hi all ...

Thought I'd throw this one out there ... Anyone think of any improvements?

- Mike

Code:
```     Dim StDate As Date, EndDate As Date
Dim DayOfWeek As Integer, DateString As String

DayOfWeek = DatePart("w", Date)
CurrentWeek = DateAdd("d", (DayOfWeek - 2) * (-1), Date)
EndDate = DateAdd("d", 6, CurrentWeek)
If DatePart("m", CurrentWeek) = DatePart("m", EndDate) Then
DateString = Format(CurrentWeek, "mmmm d") & " - " & DatePart("d", EndDate)
Else
DateString = Format(CurrentWeek, "mmm d") & " - " & Format(EndDate, "mmm d")
End If
Week1Lbl.Caption = DateString```

This yields: June 14 - 20

2. (Making Your Life Easy)
Join Date
Feb 2004
Location
New Zealand
Posts
1,482
Provided Answers: 11
I use the code for all my date reporting everything get taken to the next saturday

Code:
```Function WEEKEND(dat) As Date
If IsNull(dat) Then Exit Function
dat = DateSerial(year(dat), Month(dat), Day(dat))
If dat Mod 7 > 0 Then
WEEKEND = dat - dat Mod 7 + 7
Else
WEEKEND = dat
End If
End Function```

3. Grand Poobah
Join Date
Sep 2003
Location
MI
Posts
3,713
Originally Posted by myle
I use the code for all my date reporting everything get taken to the next saturday

Code:
```Function WEEKEND(dat) As Date
If IsNull(dat) Then Exit Function
dat = DateSerial(year(dat), Month(dat), Day(dat))
If dat Mod 7 > 0 Then
WEEKEND = dat - dat Mod 7 + 7
Else
WEEKEND = dat
End If
End Function```
Thanks for the code snippet ... Who knows ... Some programming kiddie can use both our routines.

4. Purveyor of Discontent
Join Date
Mar 2003
Location
The Bottom of The Barrel
Posts
6,102
Provided Answers: 1
Another approach:

Code:
```Public Function GetWeekEnds(DateIn As Date, OutType As Integer) As Date
Dim DayOfWeek As Integer
DayOfWeek = DatePart("w", DateIn)
If OutType = 0 Then
GetWeekEnds = DateAdd("d", (7 - DayOfWeek), DateIn)
Else
GetWeekEnds = DateAdd("d", (7 - DayOfWeek) - 6, DateIn)
End If
End Function```
Usage:

Beginning of week: GetWeekEnds(Date, 0)
End of Week: GetWeekEnds(Date, 1)

I'm lazy so I didn't put error checking on the toggle bit, but whatever.

5. (Making Your Life Easy)
Join Date
Feb 2004
Location
New Zealand
Posts
1,482
Provided Answers: 11
M owen

Here a other one I Use

Code:
```Function MY_YEAR(F As Date)
Dim f1 As Integer
Dim f2 As Integer
If IsNull(F) Then Exit Function
f1 = year(F)
f2 = Month(F)
f3 = 3  '<= start of the year
If f2 > f3 Then
MY_YEAR = Right(Str(f1 + 0), 2) + "/" + Right(Str(f1 + 1), 2)
Else
MY_YEAR = Right(Str(f1 - 1), 2) + "/" + Right(Str(f1 + 0), 2)
End If
End Function```
Use it for report What Working Year is it

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•