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
 General SQL Server Forums
 New to SQL Server Programming
 Get Current Day then Prior weeks Sat-Sun dates

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 Finish

I 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]
Go to Top of Page

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)
Go to Top of Page

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]
Go to Top of Page
   

- Advertisement -