Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8516

Re: Grouping by week, need help with group name.

$
0
0

If you are using a Command object you could add a column to your query with this logic and then group on it.  Here is an example using SQL Server. 

 

DECLARE @MyDate    AS DATE

DECLARE @WeekNumber AS INT

DECLARE @FirstDayOfWeek AS DATE

DECLARE @LastDayOfWeek AS DATE

 

SET @MyDate = '01/04/2015'

SET @WeekNumber = DATEPART(WEEK, @MyDate) - 1  -- subtract one week because SQL Server considers 01/04/2015 to be Week 2

SET @FirstDayOfWeek = DATEADD(DAY, (0 + (DATEPART(dw, @MyDate) - 1 + 7) % 7) * -1, @MyDate)

SET @LastDayOfWeek = DATEADD(DAY, (-6 + (DATEPART(dw, @MyDate) - 1 + 7) % 7) * -1, @MyDate)

 

 

SELECT 'Week ' + CONVERT(VARCHAR(2), @WeekNumber) + ' (' +

CONVERT(VARCHAR(10), @FirstDayOfWeek, 101) + ' - ' +

CONVERT(VARCHAR(10), @LastDayOfWeek, 101) + ')'

 

If you are not using a Command object, then you are going to have to do this in Crystal formulas.  I'll let you figure that out.  Or maybe Abhilash Kumar will come to the rescue. 

 

I have given more details on the first and last day of week logic and much more in myFirst day of previous week with a twist document.

 

Enjoy,

 

Noel


Viewing all articles
Browse latest Browse all 8516

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>