Given a week-day (1-7), how can I calculate what that week-day’s last date was?
Example: Today is Wednesday, 2008/11/12, and I want to know what last Friday’s date was.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If
todayis the current day of the week, then you can use something like:This assumes that Friday is represented by day number 6 of the week (that is, 1 represents Sunday). Then subtract
days_since_fridayfrom the current date, and you’ll get the date of the end of last week.The above expression is slightly more complicated than it needs to be. If your day-of-week started at 0 for Sunday, it simplifies to:
or