February 6, 2018 at 7:01 am
meichmann - Tuesday, February 6, 2018 5:23 AMJeff Moden - Monday, February 5, 2018 2:40 PMmeichmann - Monday, February 5, 2018 6:06 AMYes it is. If the month, or even year rolls over during the business week, then it's ok. 🙂
Perfect (and smart, too). Are you folks actually following an ISO calendar or is it just for this report?
It's just for this report. Not following an ISO calendar. 🙂
K. Thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 6, 2018 at 7:10 am
Jeff Moden - Tuesday, February 6, 2018 7:01 AMmeichmann - Tuesday, February 6, 2018 5:23 AMJeff Moden - Monday, February 5, 2018 2:40 PMmeichmann - Monday, February 5, 2018 6:06 AMYes it is. If the month, or even year rolls over during the business week, then it's ok. 🙂
Perfect (and smart, too). Are you folks actually following an ISO calendar or is it just for this report?
It's just for this report. Not following an ISO calendar. 🙂
K. Thanks for the feedback.
Thank you!
March 3, 2019 at 12:03 pm
ScottPletcher - Thursday, February 1, 2018 7:58 AM
SELECT DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date]) AS [Week of],
COUNT(*) AS Count
FROM dbo.your_table_name
GROUP BY DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date])
Hi Scott,
I'm doing some research here to resolve an issue an came across your posting. Which is perfect if the week starts on a Monday.
But our week starts on Sunday. My report has start date and end date parameters and users are instructed to always select a Sunday to start.
Could you help me.
Thank you
March 4, 2019 at 7:26 am
Bravo Jeff +1
March 4, 2019 at 9:32 am
omelo - Sunday, March 3, 2019 12:03 PMScottPletcher - Thursday, February 1, 2018 7:58 AM
SELECT DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date]) AS [Week of],
COUNT(*) AS Count
FROM dbo.your_table_name
GROUP BY DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date])Hi Scott,
I'm doing some research here to resolve an issue an came across your posting. Which is perfect if the week starts on a Monday.
But our week starts on Sunday. My report has start date and end date parameters and users are instructed to always select a Sunday to start.
Could you help me.
Thank you
Yes. Change the 0s to 6s. It should be just that easy. That's one reason I stick to that pattern for this type of calc. And it's logical if you think about it: if day 0 is Monday, then day 1 would be Tuesday, ..., 6 would be Sunday.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
March 4, 2019 at 9:33 am
omelo - Sunday, March 3, 2019 12:03 PMScottPletcher - Thursday, February 1, 2018 7:58 AM
SELECT DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date]) AS [Week of],
COUNT(*) AS Count
FROM dbo.your_table_name
GROUP BY DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date])Hi Scott,
I'm doing some research here to resolve an issue an came across your posting. Which is perfect if the week starts on a Monday.
But our week starts on Sunday. My report has start date and end date parameters and users are instructed to always select a Sunday to start.
Could you help me.
Thank you
Just use a -1 instead of the zero. -1 equals '1899-12-31' which was a Sunday.
March 4, 2019 at 9:54 am
ScottPletcher - Monday, March 4, 2019 9:32 AMomelo - Sunday, March 3, 2019 12:03 PMScottPletcher - Thursday, February 1, 2018 7:58 AM
SELECT DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date]) AS [Week of],
COUNT(*) AS Count
FROM dbo.your_table_name
GROUP BY DATEADD(DAY, -DATEDIFF(DAY, 0, [Order Date]) % 7, [Order Date])Hi Scott,
I'm doing some research here to resolve an issue an came across your posting. Which is perfect if the week starts on a Monday.
But our week starts on Sunday. My report has start date and end date parameters and users are instructed to always select a Sunday to start.
Could you help me.
Thank youYes. Change the 0s to 6s. It should be just that easy. That's one reason I stick to that pattern for this type of calc. And it's logical if you think about it: if day 0 is Monday, then day 1 would be Tuesday, ..., 6 would be Sunday.
It works perfectly!!!😀
DATEADD(DAY, -DATEDIFF(DAY, 6, [transdate]) % 7, [transdate]) AS Week
I get the results from sunday to Saturday, even for the weeks that overlap years. Like Dec 30/2018 to Jan 5/2019.
I appreciated all responses!
August 4, 2021 at 9:14 am
hello ScottPletcher,
would you please help me here:
it's almost similar problem but syntax not working and couldn't translate it
Viewing 8 posts - 16 through 22 (of 22 total)
You must be logged in to reply to this topic. Login to reply