I needed to get the Week Number for the Month and the Quarter for a BI Application.
I was able to retrieve it using the below query.
SELECT DATEDIFF(WEEK, DATEADD(MONTH, DATEDIFF(MONTH, 0, '2012-03-17'), 0), '2012-03-17') +1 AS WeekNoMonth,DATEDIFF(WEEK, DATEADD(QUARTER, DATEDIFF(QUARTER, 0, '2012-03-17'), 0), '2012-03-17') +1 AS WeekNoQuarter
The results are WeekNoMonth=3 and WeekNoQuarter=11
I was able to retrieve it using the below query.
SELECT DATEDIFF(WEEK, DATEADD(MONTH, DATEDIFF(MONTH, 0, '2012-03-17'), 0), '2012-03-17') +1 AS WeekNoMonth,DATEDIFF(WEEK, DATEADD(QUARTER, DATEDIFF(QUARTER, 0, '2012-03-17'), 0), '2012-03-17') +1 AS WeekNoQuarter
The results are WeekNoMonth=3 and WeekNoQuarter=11
This comment has been removed by a blog administrator.
ReplyDelete