Friday, June 12, 2015

First Day and Last Day of Current Week

While developing one of the portal, I come in difficulty to generate first day and last day of the current week to filter data. After googling, I found out the followings to generate first day of current week and last day of current week:

To get first day of current week:
SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)

To get last day of current week:
SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)

That really save me a lot to filter data.

No comments: