In order to get timestamp for start of the week and end of the week I do the following.
SET @currentTimestamp = DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()); SET @currentDate = DATEADD(s, @currentTimestamp, '19700101'); SET @currentWeek = DATEPART(wk, @currentDate); SET @starter = 1451654325; SET @weekSize = 604800; SET @beginOfWeek = @starter + ((@weekSize) * (@currentWeek - 2)); SET @endOfWeek = @starter + ((@weekSize) * (@currentWeek - 1));
It is necessary for the future for query like...
Submit_Date BETWEEN @beginOfWeek AND @endOfWeek
For doing something as part of current week.
Can I make the code more elegant and beautiful?