sql server - Get last 5 week range -


i need load info last 5 weeks in 5 seperate lists, no matter date. week, i'll need last 5 weeks before one. next week i'll need last 5 weeks before one, includes one. if makes sense , doesn't confuse you?

so basically:

..between '2015-09-21' , '2015-09-27' 

has replaced with:

select dateadd(wk,datediff(wk,7,getdate()),0) , dateadd(wk,datediff(wk,7,getdate()),6) 

this works fine, same second week:

select dateadd(wk,datediff(wk,14,getdate()),0) , dateadd(wk,datediff(wk,14,getdate()),6) 

but on, doesn't work anymore. different results when add date manually.

select dateadd(wk,datediff(wk,21,getdate()),0) , dateadd(wk,datediff(wk,21,getdate()),6) 

am doing wrong in code?

if use between datetime data type should add 7 days beginning of week find end of week

dateadd(wk,datediff(wk,21,getdate()),7) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -