how to get only records from this week?
  •  SELECT *
    FROM task t
    WHERE t.date >= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) / 7 * 7, 0)
    AND t.date <= DATEADD(DAY, DATEDIFF(DAY, -1, GETDATE()), 0)
  • 1 Comment sorted by
  • Vote Up0Vote Down atirnaveedatirnaveed
    17.50 Karma Accepted Answer
    DECLARE @FIRSTDAY as DATETIME
    DECLARE @LASTDAY as DATETIME

    SET @FIRSTDAY = DATEADD(DD, DATEDIFF(DD, 0, DATEADD(DAY, 0 - (DATEPART(DW,GETDATE()) - 2), GETDATE())), 0) -- Monday
    SET @LASTDAY = DATEADD(DD, DATEDIFF(DD, 0, DATEADD(DAY, 0 - (DATEPART(DW, GETDATE()) - 7), GETDATE())), 0) -- Saturday

    SELECT *
    FROM task t
    WHERE t.date >=@FIRSTDAY
    AND t.date <= <a href="/profile/LASTDAY">@LASTDAY

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Optimum Creative