In this article, we will learn how to get First day and Last Day of a current week, the previous week and the last week in SQL Server.
To get the first day of the previous week in SQL Server, a statement is as follow:
SELECT DATEADD(wk, -1, DATEADD(DAY, 1-DATEPART(WEEKDAY, GETDATE()), DATEDIFF(dd, 0, GETDATE()))) as 'First Day of the Previous Week';
First Day of the Previous Week
---------------------------------------
2019-04-14 00:00:00.000
To get the last day of the previous week in SQL Server, a statement is as follow:
SELECT DATEADD(wk, 0, DATEADD(DAY, 0-DATEPART(WEEKDAY, GETDATE()), DATEDIFF(dd, 0, GETDATE()))) as 'Last Day of the Previous Week';
Last Day of the Previous Week
--------------------------------------
2019-04-20 00:00:00.000
To get the first day of the current week in SQL Server, a statement is as follow:
SELECT DATEADD(wk, 0, DATEADD(DAY, 1-DATEPART(WEEKDAY, GETDATE()), DATEDIFF(dd, 0, GETDATE()))) as 'First Day of the Current Week';
First Day of the Current Week
--------------------------------------
2019-04-21 00:00:00.000
To get the last day of the current week in SQL Server, a statement is as follow:
SELECT DATEADD(wk, 1, DATEADD(DAY, 0-DATEPART(WEEKDAY, GETDATE()), DATEDIFF(dd, 0, GETDATE()))) as 'Last Day of the Current Week';
Last Day of the Current Week
----------------------------
2019-04-27 00:00:00.000
To get the first day of the next week in SQL Server, a statement is as follow:
SELECT DATEADD(wk, 1, DATEADD(DAY, 1-DATEPART(WEEKDAY, GETDATE()), DATEDIFF(dd, 0, GETDATE()))) as 'First Day of the Next Week';
First Day of the Next Week
----------------------------------
2019-04-28 00:00:00.000
To get the last day of the next week in SQL Server, a statement is as follow:
SELECT DATEADD(wk, 2, DATEADD(DAY, 0-DATEPART(WEEKDAY, GETDATE()), DATEDIFF(dd, 0, GETDATE()))) as 'Last Day Next Week';
Last Day of the Next Week
---------------------------------
2019-05-04 00:00:00.000
I hope this article will help you to understand how to get First day and Last Day of a current week, the previous week and the last week in SQL Server.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments