How to get first & last day of the previous Week

Below given script may help you.

This query wil return first day of the previous Week


SELECT CONVERT(DATE,DATEADD(WK, DATEDIFF(WK, 0, GETDATE()) - 1, 0)) First_Day_Of_Prev_Week

This query wil return last day of the previous Week


SELECT CONVERT(DATE,DATEADD(WK, DATEDIFF(WK, 0, GETDATE()) - 1, 0) + 6) Last_Day_OF_Prev_Week



This query will return first day of the current week

SELECT CONVERT(DATE,DATEADD(WK, DATEDIFF(WK, 0, GETDATE()) , 0))
 

No comments:

Post a Comment

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...