Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2017
    Posts
    1

    Unanswered: Retreive last 7 days of data

    I run a weekly report and need to pull all the rows where the record was entered within the last 7 days.


    I tried:

    convert(varchar, casdOpeningDate, 112) >= convert(varchar, getdate(), 112) -7 and convert(varchar, casdOpeningDate, 112) <= convert(varchar, getdate(), 112) )

    it seems to work mid-month but if I run the report from the 1st to the 6th of the month, it doesn't give me the last few days of the previous month.

    Any help is appreciated.

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,862
    Provided Answers: 17
    You should use the date functions, instead of converting to VARCHAR. Try

    Code:
    where casdOpeningDate > convert(date, dateadd(dd, -7, getdate()))
    The conversion to DATE datatype here is simply to strip off the time portion of the data.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •