I need some help
I am trying to get the Previous sunday from a date (for example 23/03/2024 should return me the sunday date of 17th March)
as I need to get the Sunday to Monday dates for a report that run for the previous week (no matter what day the report would be run this week it would always report back the previous Monday to Sunday dates)
This is what I have so for
Private Function GetPreviousWeekDayDate(inputDate As Date) As Date
' Calculate the number of days to subtract to find the previous week day
Dim daysToSubtract As Integer
daysToSubtract = WeekDay(inputDate + 5) Mod 7
' Subtract the calculated days from the input date
Dim previousWeekDayDate As Date
previousWeekDayDate = inputDate - daysToSubtract
Return previousWeekDayDate
End Function
Private Function GetSundayDate(inputDate As Date) As Date
' Calculate the number of days to subtract to find the Sunday date
Dim daysToSubtract As Integer
daysToSubtract = WeekDay(inputDate) - 1 ' Sunday is 1, Saturday is 7
' Subtract the calculated days from the input date
Dim sundayDate As Date
sundayDate = inputDate - daysToSubtract
Return sundayDate
End Function
This is how i am calling them at the moment
dtStartDate = GetPreviousWeekDayDate(Now)
dtEndDate = GetSundayDate(dtStartDate)
Dim StartOfWeekDay As String = "Monday " & Format(dtStartDate, "dd/mm/yyyy")
Dim EndOfWeekDay As String = "Sunday " & Format(dtEndDate, "dd/mm/yyyy")
But I am getting at the moment getting Start Date : Monday 19/03/2024 and End Date : Sunday 18/03/2024
if anyone has any better ideas as how to get previous weeks dates I would be most grateful as I have been on this report Since Saturday afternoon