1

My scenario: I have SalesDate (eg: 2007-01-01 to 2016-01-01) filed like this up to todate and have daily date. Now I have to find this salesdate belong to which week.

Condition

Start day of week is Sunday. Based on year, if new year starts week count start as 1.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • can u pl refer this link which may help you http://stackoverflow.com/questions/13116222/how-to-get-week-number-of-the-month-from-the-date-in-sql-server-2008 – yuvi Jan 08 '16 at 04:07

1 Answers1

3

Try something like below,

DECLARE @SalesDate DATETIME = '2007-01-01'
SELECT DATEDIFF(WEEK, DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(MONTH, DATEDIFF(MONTH, 0, @SalesDate), 0)), 0), @SalesDate - 1) + 1 WeekD, @SalesDate SalesDate

OR

DECLARE @SalesDate DATETIME = '2007-01-01'
SELECT DATEPART(WEEK,@SalesDate) WeekNumber, @SalesDate SalesDate
Pedram
  • 6,256
  • 10
  • 65
  • 87