Finding the Last Day of the Week.
How can we determine the weekend date or the first day of a week using the current date? Similarly, how can we calculate the first or last day of any week when given a specific date?
When preparing a report or query that requires the start or end date of a week as a filter, date-based calculation is necessary to find the input date. For example, you may need the weekend date to group weekly sales, filter the records, or generate Reports for distribution.
Wherever this is needed, you can use the following simple expression to calculate the weekend date of the current week:
The Simple Expressions
LastDayOfWeek = Date()- WeekDay(date())+7
If the current date is 14th June 2017 (or any date between 11 and 17 June 2017), then the value returned in variable LastDayOfWeek = 17th June 2017.
Example-1
To find the current week's first day, use the following method:
FirstDayOfWeek = date()- WeekDay(date())+1
Assuming the current date is 14th June 2017 (or any date between 11 and 17 June 2017), the expression returns 11th June 2017 in the variable FirstDayofWeek.
Example-2
By giving a specific date as input to the expression to find the last day of the week:
dtValue = #06/27/2017# LastDayOfWeek = dtValue - WeekDay(dtValue)+7 Result: 1st July 2017
Example-3
If you would like to do it differently, then try the following expression:
x = #06/27/2017#
'To find the last-day date of the Week:
LastDayofWeek = DateSerial(Year(Date()),1,1)+DatePart("ww",x)*7-1
Result: 1st July, 2017
'To find the first-day date of the Week.
FirstDayofWeek = DateSerial(Year(Date()),1,1)+DatePart("ww",x)*7-7
Result: 25th June, 2017
WeekLastDay Function
Define it as a Function in a VBA Module and call it wherever you want, with a date value as the parameter. The Sample Function code is given below:
Public Function WeekLastDay(ByVal dtVal As Date) As Date 'Date value as input WeekLastDay = dtVal - WeekDay(dtVal) + 7 End Function
WeekFirstDay Function
Public Function WeekFirstDay(ByVal dtVal As Date) As Date
'Date value as input
WeekFirstDay = dtVal - WeekDay(dtVal) + 1
End Function









