1
0
mirror of https://github.com/alex-bochkov/ssms-addin.git synced 2025-11-23 22:04:53 +02:00
Files
ssms-addin/QueryTemplates/Common Scripts/dates-functions.sql
2019-04-28 12:23:31 -07:00

15 lines
611 B
SQL

-- 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)