1
0
mirror of https://github.com/alex-bochkov/ssms-addin.git synced 2025-11-29 22:08:12 +02:00

Create dates-functions.sql

This commit is contained in:
Alexey Bochkov
2019-04-28 12:23:31 -07:00
committed by GitHub
parent 441bc5c42e
commit 494b779c0c

View File

@@ -0,0 +1,14 @@
-- beginning of hour
SELECT DATEADD(hour, DATEDIFF(hour, 0, GETDATE()), 0)
-- beginning of day
SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
-- yeasterday
SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()), -1)
-- beginning of the month
SELECT DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
-- enf of the month
SELECT DATEADD(month, DATEDIFF(month, 0, GETDATE()), -1)
-- start of next month:
SELECT DATEADD(month, DATEDIFF(month, 0, GETDATE()), 31)
-- adjust to nearest 4 hours interval: 00:00, 04:00, 08:00, 12:00, 16:00, 20:00
SELECT DATEADD(hour, ROUND(DATEDIFF(hour, 0, GETDATE()) / 4, 0, 1) * 4, 0)