Getting the first day of the week, last day of the week and last day of the month using T-SQL date functions
Getting First Day of the week
DECLARE @Date datetime SET @Date = '2001/08/31' SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS 'First day of the week'
Getting Last Day of the week
DECLARE @Date datetime SET @Date = '2001/08/31' SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last day of the week'
Getting Last Day of the Month
DECLARE @Date datetime SET @Date = '2001/08/31' SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS 'Last day of the month'
|
No responses found. Be the first to respond and make money from revenue sharing program.
|