Hi,
I'm just assuming your dates are stored as Sybase datetime values. If not, this won't help much, but this expression will give you the prior week's Sunday no matter what day of the week you run it on:
dateadd (day
, -7 - (datepart (weekday, getDate()) - 1)
, getdate())
What this does is subtract seven days from the current date and the current prior weekday. In short, on Monday, it'd subtract 8 days; on Friday 12; and so on.
Just by way of explanation, the dateadd function takes a unit
day in this example so it's adding days. Since we want to subtract days, we start with a -7 value and go backward beyond that based on what day of the week it is.
datepart returns a part of the date (in this case, the weekday. Since
datepart returns 1 for Sunday (such things tend to be 1-based in Sybase), we subtract 1 from that before doing the subtraction from -7 so that we go back the right number of days.
You might find something like this useful:
declare @lastSunday datetime, @lastSaturday datetime
select @lastSunday =
dateadd (day
, -7 - (datepart (weekday, getDate()) - 1)
, getdate()
)
select @lastSaturday = dateadd (day, 6, @lastSunday)
HTH,
J M Craig
Alpha-G Consulting, LLC
nsjmcraig@netscape.net