I'm wanting to format a date to month then week ... eg
June 06 Week 1 would cover date range thursday 01/06/06 to Saturday 03/06/06
June 06 Week 2 would cover date range Sunday 04/06/06 to Saturday 10/06/06
Public Function FormatMonthWeek(dtDate As Date) As String
Dim FirstDay As Date
Dim PrevSunday As Date
Dim x As Integer
FirstDay = DateSerial(Year(dtDate), Month(dtDate), 1)
PrevSunday = (FirstDay - Weekday(FirstDay)) + 1
x = 0
Do Until PrevSunday > dtDate
PrevSunday = PrevSunday + 7
x = x + 1
Loop
FormatMonthWeek = Format(dtDate, "mmmm yyyy") & " Week " & x
End Function
A function is not an absolute necessity, the operation may be performed in a single (somewhat complex) expression (minor variation to rubbernilly's excellent suggestion above:
June Week 1 Monday 29 May to Friday 2 June
June Week 2 Monday 5 June to Friday 9 June
June Week 3 Monday 12 June to Friday 16 June
June Week 4 Monday 19 June to Friday 23 June
June Week 5 Monday 26 June to Friday 30 June
July Week 1 Monday 3 July to Friday 7 July
If you could help out with another function, that would be faboulous!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.