Query the SQL statement for the next Sunday (Sunday is the first day) of the week of the given date.
Query the SQL statement for the next Sunday (Sunday is the first day) of the week of the given date.
Query the SQL statement for the next Sunday (Sunday is the first day) of the week of the given date.
Declare @ date datetime
Set @ date = getdate ()
-- Idea: add one week to the Sunday of the current log
-- The return value of datepart (weekday, date) is related to @ datefirst.
Set datefirst 7 -- or set it to set language us_english; (Sunday is the first day)
Select dateadd (week, 1, dateadd (day, 1-datepart (weekday, @ date), @ date) as 'Day of next week, Sunday'
-- One week equals 7 days
Select dateadd (day, 7, dateadd (day, 1-datepart (weekday, @ date), @ date) as 'Day of next week, Sunday'
-- Simplified
Select dateadd (day, 8-datepart (weekday, @ date), @ date) as 'Day of next week, Sunday'
-- Next Sunday, it is irrelevant to the SQL server language version or @ datefirst
Select dateadd (week, 1 + datediff (week,-1, @ date),-1) as 'next Sunday'
-- Or
Select dateadd (week, datediff (week,-1, @ date), 6) as 'next Sunday'
Go