determining the date of the last Sunday
Posted on 2009-05-05
I need to figure out what the date is on the Sunday prior to the current day and the date of the Sunday the week before that. For example, today is Tuesday May 5. I need to capture the date variable of the Sunday of the current week which in the example would be Sunday, May 3. Then I also need to capture the week prior to that, so I would need to capture Sunday, April 26.
Is there even a way to do this? I'm needing these dates because I have a reporting tool with a drop down of specific periods of time. For example, in the dropdown I have for choices, This Week, Last Week, This Month, Last Month, This Year, Last Year. So when the end user chooses one of these periods, it queries the database for that specific period of time. For example, the end user chooses Last Month. So in my query, it would get all records from April 1 to April 30. I have that done...but not sure on how to get the weeks.
So if the end user chooses This Week, I want the query to give results for records of between May 3 and May 9. If the end user chooses Last Week, I want the query to give results for records between April 26 and May 2.