Getdate - 7days

  • Hi all,

    Hopefully a quick question. I have been trying to tweak a view for the network admin, he wants this view to show information from today back 7 days.

    This is what I have:

    WHERE (CONVERT(varchar(12), dbo.ACADEMIC.SEPARATION_DATE, 101)

    < = (CONVERT(varchar(12),-7 GETDATE() , 101)

    I know it's wrong...but where is it wrong is the million dollar question? Thanks in advance

    Laura

  • The < is backwards you have to use > to get everything 7 days back thru today plus you need a DATEADD with day as datepart to work on -7 as what to add (so subtract 7 days) from GETDATE() to get today. Also don't need the convert on the SEPARATION_DATE as it will slow your query down. Try

    WHERE dbo.ACADEMIC.SEPARATION_DATE

    >= (CONVERT(varchar(12),DATEADD(d,-7, GETDATE()) , 101)

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Thanks, I'll check it out.

    Laura

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply