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.
| Author |
Topic |
|
srucker
Starting Member
26 Posts |
Posted - 2009-07-14 : 12:04:47
|
| I am looking to get the past weeks data from the current day of the week.So far I have been able to get the week range from a specific date.Select Convert(varchar, DateAdd(dd, -(DatePart(dw, GetDate()) + 5), GetDate()), 101) as Start,Convert(varchar, DateAdd(dd, (1 - DatePart(dw, GetDate())), GetDate()), 101) as FinishI am getting stuck on the other portion of this which would be to identify the current day of the week and then get the Sun - Sat period for the previous week.A push in the right direction would be very much appreciated.Regards |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-14 : 12:54:51
|
| [code]SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE())-1,0) AS StartDate,DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)-1 AS EndDate[/code] |
 |
|
|
srucker
Starting Member
26 Posts |
Posted - 2009-07-14 : 13:03:46
|
| This returned 7/6 - 7/12 which is Monday-Sunday.How could I get Sunday - Saturday returned instead (7/5 - 7/11) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-14 : 13:05:57
|
| [code]SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE())-1,0)-1 AS StartDate,DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)-2 AS EndDate[/code] |
 |
|
|
|
|
|
|
|