Calculating the date for the day of the week
If today
is the current day of the week, you can use something like:
days_since_friday = (((today - 1) + 7) - (6 - 1)) % 7
This assumes that Friday is represented by the day of the 6th of the week (that is, 1 represents Sunday). Then subtract days_since_friday
from the current date and you get the end date of the last week.
The above expression is a little more complicated than it should be. If your day of the week started at 0 on Sunday, it is simplified:
days_since_friday = ((today + 7) - 5) % 7
or
days_since_friday = (today + 2) % 7
source to share
Generally? See Calendar Calculations .
In this narrower case during the previous week? Find the difference in days (Friday = 5, Wednesday = 3). Find the difference in weeks (last week = -7 days). When you've found the offset in days + weeks, apply that offset to the calendar date.
source to share