I need SQL for getting current month start and end (1 of current month to 28/30/31 of current month) in yyyyMMdd format and for week too, but week should be from Sunday to Saturday
I used for week start date
SELECT CONVERT(INT, CONVERT(VARCHAR(8), DATEADD(WEEK, DATEDIFF(WEEK, 0, SYSDATETIME()), 0), 112)
for week end date
SELECT CONVERT(INT, CONVERT(VARCHAR(8), DATEADD(WEEK, DATEDIFF(WEEK, 0, SYSDATETIME()) + 1, 0), 112))
For month start
SELECT CONVERT(INT, CONVERT(VARCHAR(6), SYSDATETIME(), 112) + '01')
for month end
SELECT CONVERT(INT, CONVERT(VARCHAR(6), DATEADD(MONTH, 1, SYSDATETIME()), 112) + '01')
But issue is week is giving me week date from Monday to Monday and month end date is giving me end date for start of next month (20160801)
The result should be
Week from 20160710 to 20160716
Month from 20160701 to 20160731
Please help me correct it.