Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date within week

Author  Topic 

skillile
Posting Yak Master

208 Posts

Posted - 2002-09-07 : 14:37:11
I want to grab all dates for the week after the user submits a date. So If user submits tue, I want sun, mon, tue, wed thr, fri, sat in return. Here is what I have but I think there must be a better way.

DECLARE @ddate smalldatetime,
@sdate smalldatetime,
@x int

SET @ddate='09-11-2002 8:00'
SET @x = datepart(dw, @ddate)
SET @sdate = dateadd(dd, (-@x+1), @ddate)

WHILE datepart(dw, @sdate) < 7
BEGIN
SELECT @sdate
SET @sdate = dateadd(dd, 1, @sdate)
END

-- I would then get the last day by adding 1


Thanks


slow down to move faster...

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-07 : 16:04:33
Take a look at this:

http://www.sqlteam.com/item.asp?ItemID=3332

Go to Top of Page
   

- Advertisement -