I've seen the following question about grouping by month:
DATEADD(MONTH, DATEDIFF(MONTH, 0, Closing_Date), 0)
How to group by month from Date field using sql
This works - but I want to run this against a specific timezone, taking DST into account.
To be specific, the Netherlands timezone: Central European Standard Time (GMT+1).
This will be GMT+2 sometimes with DST.
In my case I have an Orders
table with an OrderDatetime
which is a DateTimeOffset(7)
. all values are UTC (+00:00).
SELECT
DATEADD(MONTH, DATEDIFF(MONTH, 0, [Orders].[OrderDateTime]), 0) AS [Month],
...
FROM
[Orders]
GROUP BY
DATEADD(MONTH, DATEDIFF(MONTH, 0, [Orders].[OrderDateTime]), 0)
What would such query look like when taking into account a specific timezone?
Bonus: I'd preferably make this configurable, so the timezone would be a parameter - what would such query look like?