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 2005 Forums
 Transact-SQL (2005)
 How to populate calendar table

Author  Topic 

vision.v1
Yak Posting Veteran

72 Posts

Posted - 2009-08-10 : 06:03:12
Hi,

In my application i want to set

@fromdate = previous week Monday i.e., 3rd August and
@todate = previous week saturday i.e., 8th August

If the week changes, then @fromdate and @todate also need to be changed
accordingly.

plz give some idea....

Sachin.Nand

2937 Posts

Posted - 2009-08-10 : 06:14:33
Not the best way but still it works

select MIN(DATEADD(dd,-6,DATEADD(wk, DATEDIFF(wk, 6, GETDATE()), 6))),
MIN(DATEADD(wk, DATEDIFF(wk,-8, GETDATE()), -8))-1


PBUH
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-08-10 : 06:51:13
Here the solution,

It will provide the previous week monday as Fromdate and Saturday as Todate.

declare @date datetime
set @date =getdate()

select @fromdate= @date-(7 +(DATEPART(weekday, @date) -2))
select @todate= @date-(7 -(7-DATEPART(weekday, @date)))

select @fromdate,@todate

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -