retrieve Data within this week using SQL


 

SET DATEFIRST 7

SELECT DATEADD(DD, 1 DATEPART(DW, getdate()), DateDiff(day, 0, GETDATE())) as beginningOfThisSunday

SELECT DATEADD(DD, 1 DATEPART(DW, getdate()), 7 + DateDiff(day, 0, GETDATE())) as beginningOfNextSunday

 

SELECT * FROM yourtable WHERE yourDTcolumn>=DATEADD(DD, 1 DATEPART(DW, getdate()), DateDiff(day, 0, GETDATE()))

AND yourDTcolumn<DATEADD(DD, 1 DATEPART(DW, getdate()), 7 + DateDiff(day, 0, GETDATE()))

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s